Ports and adapters / hexagonal architecture - clarification of terms and implementation

后端 未结 4 493
一个人的身影
一个人的身影 2021-01-30 04:31

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

4条回答
  •  迷失自我
    2021-01-30 04:53

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

    According to my understanding the port is an expression of your interface.

    The port:

    • Defines the exposure of the core's functionality (for 'incoming' ports)
    • Defines the core's view of the outside world (for 'outgoing' ports)

    The adapter:

    • Is located outside the component (hexagon)
    • Is used to ensure that the transport between port and the target happens in a way that satisfies the contract with the port's interface
    • Is what you replace (using dependency injection) to test the hexagon

    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.

    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.

提交回复
热议问题