端口和适配器/六边形架构 - 术语和实现的说明 [英] Ports and adapters / hexagonal architecture - clarification of terms and implementation

查看:33
本文介绍了端口和适配器/六边形架构 - 术语和实现的说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读有关 Ports & 的不同来源后适配器架构,包括 Alistair Cockburn 的原创文章我仍然不确定术语端口"和适配器"的确切含义——尤其是在将这些概念映射到实现工件时.

After reading different sources about the Ports & Adapters architecture including Alistair Cockburn's original article I am still not sure about the definite meaning of the terms "port" and "adapter" - especially when it comes to mapping these concepts to implementation artifacts.

几个来源(例如这篇文章)暗示这个架构模式中的端口是最外面的工件,然后是中间层中的适配器,在端口端口之间进行转换.应用是核心.

Several sources (e. g. this post) imply that the ports in this architecture pattern are artifacts at the very outside, followed by the adapters in the intermediate layer that translate between the ports and the application that is at the heart.

然而,在 Cockburn 的原始文章中,端口出现在适配器层的外部和内部,取决于通信方向:

However, in Cockburn's original article the ports appear at the outside as well as on the inside of the adapter layer dependent on the direction of communication:

  • 入站通信:当事件从外部世界到达某个端口时,特定于技术的适配器会将其转换为可用的过程调用或消息并将其传递给应用程序."
  • 出站通信:当应用程序有内容要发送时,它会通过端口将其发送到适配器,该适配器会创建接收技术(人工或自动)所需的适当信号."

实际上对我来说,所有外部"方法和内部和外部"方法都没有意义 - 我会将 端口 视为总是放置在应用程序旁边的工件,无论方向如何的沟通.Imo 这也与 portadapter 比喻一致:例如.有一个带串口的设备,要将另一个没有串口的设备连接到这个我需要一个适配器,从我的设备的角度来适应入站和出站通信.

Actually for me neither the "all outside" approach nor the "inside and outside" approach make sense - I would see the ports as artifacts that are always placed next to the application regardless of the direction of communication. Imo this would also be consistent with the port and adapter metaphors: E. g. having a device with a serial port, to connect another device without a serial port to this I'd need an adapter that adapts inbound and outbound communication from the viewpoint of my device.

在实现这个架构时,我会看到端口的定义,而不是我的应用程序的一部分,在那里我会看到不同的适配器我的应用程序的外部".例如单个端口的实现可以由一个facade(由适配器调用以进行入站通信)和一个interface(由用于出站通信的适配器).

Coming to the implementation of this architecture I'd see the definition of the ports rather as a part of my application where I'd see the different adapters as being "outside" of my application. E. g. an implementation of a single port could consist of a facade (to be called by adapters for inbound communication) and an interface (to be implemented by adapters for outbound communication).

术语端口适配器的正确含义是什么?如何将这些概念映射到实现工件?

What is the correct meaning of the terms port and adapter and how can these concepts be mapped to implementation artifacts?

更新:

找到这篇文章,与我的理解相似.问题是是否存在某种共同协议.

Found this article which resembles my understanding. The question remains if there is some kind of common agreement.

推荐答案

inf3rno 给出了一个很好的答案,澄清了最初的问题,但强调端口和适配器的一些其他用途可能会很有用.

inf3rno gave a good answer which clarifies the original question, but it may be useful to highlight some other uses for ports and adapters.

据我了解端口是你界面的一种表达.

端口:

  • 定义核心功能的暴露(对于传入"端口)
  • 定义核心对外部世界的看法(对于传出"端口)

适配器:

  • 位于组件外(六边形)
  • 用于确保端口和目标之间的传输以满足与端口接口的约定的方式进行
  • 是你替换(使用依赖注入)来测试六边形

端口应该接受适配器并确保适配器实现接口.然后它应该只调用适配器上的适当方法/函数.

The port should accept the adapter and make sure that the adapter implements the interface. Then it should merely call the appropriate methods/functions on the adapter.

该端口应包含在通信测试中.在这种情况下,模拟"的是两个相邻六边形(或一个六边形和一个服务)的核心并测试端口/适配器/适配器/端口组件.

The port should be included in communication testing. In that case, what is 'mocked out' is the cores of two neighbouring hexagons (or a hexagon and a service) and test the port/adapter/adapter/port assembly.

有关更多信息,您可以查看 James Gardner 和我在伦敦的 Skillsmatter 微服务中关于六边形微服务的讨论 2014 年 7 月见面.

For more information you can view the talk about Hexagonal Microservices that James Gardner and I gave at London's Skillsmatter Microservices meetup in July 2014.

这篇关于端口和适配器/六边形架构 - 术语和实现的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆