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

后端 未结 4 494
一个人的身影
一个人的身影 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

    Someone at my work did a great internal presentation on this architecture. At the end, during question time, another colleague asked:

    Isn't this just a layered architecture with a different name and drawn differently?

    And, to be honest, that's true to a large extent. For many applications, a hexagonal architecture will be structured identically to a layered architecture, with a few specific details:

    • There is increased discipline in defining interfaces between each layer (the ports), rather than calling impl to impl.
    • There is a focus on "the core" (business logic) as being the most important layer, with all other layers (the adapters) being viewed as somewhat subservient.
    • The focus on defining interfaces from the perspective of the core prevents the language of the adapters from leaking into the core. For example, if you're putting your persistence (e.g. Hibernate) into an adapter, then you should not have any @Entity classes in your core.

    You can see that, even when doing all these things, it's still just a layered architecture, just with the boundaries between layers being quite strict and a focus on the central layer.

    So, to specifically answer the question, you can understand ports and adapaters by recognising that ports are the interfaces into and out of the core, and adapters are just the implementation layers that are not the core.

提交回复
热议问题