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:

  1. The single responsibility principle says that a class should have only one reason to change. The class should only execute one functionality.
  2. The open-close principle says that a class should be opened to extension, but closed to modification.
  3. Liskov’s substitution principle says that objects of a superclass should be replaceable with objects of its subclasses without breaking the system.
  4. 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.
  5. 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