In this article, I mainly share about the idea, philosophy and importance features of Clean Architecture
- Clean Architecture is like all other architecture, it is multi-layer/layer architecture.
- The philosophy of this architecture considers business rules (enterprise & application) to be the most important, which means it isolates the business rules part. So we see that entities and use cases are the two most important layers and the center of the circle. And interface adapters and frameworks & drivers are elements and are placed at the outermost of the circle.
- The circles represent the layers, the more outside, the more detailed (low level/details), the more in the center, the more abstract (high level)
The circles represent the layers, the more outside, the more detailed (low level/details), the more in the center, the more abstract (high level) - This architecture uses Dependency Inversion
- High level does not depend on low level, they depend on abstraction
- Abstraction does not depend on its implementations/details
There is confusion for beginners to approach this architecture when looking at the moving "arrow" on the figure. It's not call direction from outside to inside but dependency direction. As mentioned above, the low level is outside the circle and the high level is inside the circle, so the philosophy of this axis is that the low level will depend on the high level.
Flow of control
- Controller and Presenter are the same color because they are interface adapters. They are implementation details and are dependent on the color red
- Use Case Output Port, Interactor and Input Port are Application Business Rules, and often when code, they are usually declared in the same place, because if these interfaces are in different places and different packages, it will be wrong Dependency Inversion or simply rather than being dependent on imports from each other, not decoupling
- Controller is where the program starts and calls into the User Case Input Port (interface).
- Use Case Interactor, it will implement the Use Case Input Port
- Use Case Interactor, it will call up the Use Case Output Port for it to go out
- Finally, Presenter will implement the Use Case Output Port
In the next article, we will go into implementing Clean Architecture.