Principles
Learn what hexagonal architecture principles are.
Hexagonal architecture has a few principles that should be followed to build well-structured components. If any of them was overlooked, it would lead to having problems in the future. Additionally, changing bad implementations can be tortuous and even worse if a system is running on production.
SOLID principles
To implement components based on hexagonal architecture, it is necessary to have a well understanding of SOLID principles. Hence they will be covered in this lesson. Basically, these principles are five:
- The single responsibility principle says that a class should have only one reason to change. The class should only execute one functionality.
- The open-close principle says that a class should be opened to extension, but closed to modification.
- Liskov’s substitution principle says that objects of a superclass should be replaceable with objects of its subclasses without breaking the system.
- The interface segregation principle says that having one interface with many defined methods that may be unrequired in some implementors is not the best approach. Thereby it should be tackled by defining different interfaces.
- The dependency inversion principle says that high-level functions should be reusable and unaffected by changes in low-level functions. To achieve it is necessary to introduce abstractions to decouple both levels from one another. This is the most important principle to implement the hexagonal architecture.
Principles of hexagonal architecture
The hexagonal architecture pattern is based on three principles. As mentioned before, they are based on SOLID principles.
Clear separation principle
There must be a clear separation of responsibilities. In any component, there is a way to reach it, a specific action to execute, and perhaps, some way to save information. To comply with this principle is important to separate those functionalities from one another. The following image shows basic general separation.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy