Relatives of Onion Architecture: Hexagonal and Clean Architecture Annotations #70
Replies: 5 comments 2 replies
-
Hi, |
Beta Was this translation helpful? Give feedback.
-
like #71 ? |
Beta Was this translation helpful? Give feedback.
-
Glad I found this discussion and the PR before creating another one. I think that a look at chronological order helps sorting out some of the confusion. Alistair Cockburn formulated P&A architecture in 2005. The original version takes a very puristic approach consisting of an application core on the "inside" which is decoupled from the technology and delivery mechanisms of the outside world. The application core has ports. Each port identifies a purposeful conversation with the "outside". Adapters provide the means to actually lead the conversiation between inside and outside. Jeffrey Palermo introduced Onion architecture "officially" in 2008. Essenstially he picked up P&A and combined it with the DDD-Layers, the adapters becoming the infrastructure ring and the application core being divided into 2 or 3 rings. P&A makes no assumption about the internal architecture of the application core whereas Onion is rather opinionated. Looking at descriptions and diagrams my impression is that from that moment on most people who state that they are doing hexagonal architecture are actually doing onion architecture. The original P&A states that all ports are fundamentally similar, which on an abstract level is useful. However, Alistair Cockburn realised that in practice adapters always come in one of two flavors. He recognized that there was an asymmetry matching the concepts of 'primary actors' and 'secondary actors' from Ivar Jacobson's Object-Oriented Software Engineering, A Use-Case-Driven Approach. The primary actor is the one who initiates and knows about the conversation whereas the secondary actor only responds to the action. Hence he named the ports 'primary/secondary port' or 'primary/secondary actor port' and the adapter 'primary/secondary adapter'. I do not know when he made this addition to P&A but I suppose it happened after 2008. Clean Architecture was introduced by Robert Martin in 2012. I suppose it is my fault, but I fail to see a difference between Clean Architecture and Onion except for namings. The common denominator of P&A, Onion and Clean is that they have ring systems (although with different numbers and names of rings) and the rule that source code dependencies can only point inwards from one ring to its neighbour. I find value in comparisons of various architectures, like the one that Herberto Graca did: how the approaches relate to each other and how you can combine them. However, I feel uneasy when it comes to 'the quest for the one architecture to rule them all' attempting to put everything togegether in one architecture model of ever growing complexity. I prefer the KISS way and choose the architectural approaches for each project anew. A concrete example is my current project: a backend that communicates with lots of external systems. Decoupling the business logic is essential here. The application core is a set of slices communicating with each other by means of application events. The implementation of the use case is essentially a distributed one. There is no single element that would qualify for a use case and thus an application service. In onion architecture this would mean just an infrastructure and a domain ring but no application ring. However, the archunit rules for onion does not allow that. That's where I realised that P&A was a better choice than onion because it is less opinionated concerning the internal structure of the application core. Bottom line: I would appreciate the addition of P&A to jMolecules but I would rather see it as a separate architecture and not as part of onion. |
Beta Was this translation helpful? Give feedback.
-
it's so complicated |
Beta Was this translation helpful? Give feedback.
-
I think we can close this discussion as support for Hexagonal architecture has been introduced with #71 and the possible introduction of support for Clean Architecture is discussed in #95. |
Beta Was this translation helpful? Give feedback.
-
I am wondering if the onion architecture is by purpose the only onion-like architecture available as annotations.
With the Clean Architecture and Hexagonal Architecture (aka Ports & Adapters), there are closely related approaches around.
See https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together for a roundup.
Would it make sense to open a PR with dedicated annotations, like port, adapter, use-case etc.?
Beta Was this translation helpful? Give feedback.
All reactions