iluwatar / java-design-patterns

Design patterns implemented in Java
https://java-design-patterns.com
Other
89.88k stars 26.58k forks source link

Hexagonal Architecture primary ports should have interfaces #586

Closed iluwatar closed 5 years ago

iluwatar commented 7 years ago

Extract from the comments of http://java-design-patterns.com/blog/build-maintainable-systems-with-hexagonal-architecture/:

Hello IIkka. First of all, you're wellcome, you don't have to say thank you to me :) I don't deserve it, I'm nobody, just someone who lately read a lot about ports&adapters architecture and trying to implement it in a new project. I think new picture you added is ok and clear. About the primary ports and interfaces... I honestly should add interfaces. Primary ports are the API of the app core, the use case boundary, and they would be described by operation contracts (method's signatures), doesn't matter if you just have one implementation for them. If tomorrow you decide to change the implementation, it would afect to the caller primary adapter. With interfaces, the adapter gets the service interface by injection, and the implementation is apart. It's a best practice in ge neral to write interfaces and implementation apart when you write a service (being this service a primary port or not). In my project primary ports are interfaces of services (the application services, the use cases of the app), and the implementation of them call (orchestrate) the domain services to achieve the goals of the use case. In such app services is where you put transactional and security concerns, they are the gate to the application.

In this task the following modifications are made:

iluwatar commented 6 years ago

@7agustibm added the interfaces for primary ports. The blog post still needs to be updated.