zakirullin / cognitive-load

🧠 Cognitive Load is what matters
Creative Commons Attribution 4.0 International
3.24k stars 65 forks source link

Example needed for onion-architecture #7

Closed mpszczolinski closed 1 year ago

mpszczolinski commented 1 year ago

Hey,

I am myself advocate of onion architecture.

You said:

we gave it all up in favour of the good old dependency inversion principle

I'd like to see an example, as for me, doing onion architecture is mainly "dependency inversion principle" plus keeping DOMAIN, BUSINESS LOGIC (Use cases) and INFRASTRUCTURE in 3 different layers, glued together with "dependency inversion principle".

I'd love to see explanation how "favour of the good old dependency inversion principle" is different from "onion architecture" so I can better understand that section.

best regards, Maciej

zakirullin commented 1 year ago

@mpszczolinski Hi there!

The onion architecture variation I know implies using layers like: domain model, domain services, application services, infrastructure. Which is more layers than you described.

3 different layers.

For me, Palermo, and some other people onion architecture is about 4+ different layers.

The point is, we tend to understand these kind of things in our own way. Then we build on this understanding. Then we have to transfer this understanding to our colleagues. And this is hard.

People spend time arguing whether their code should be placed in application services layer or domain services layer. People start thinking in terms of horizontal layers.

If we spend time thinking about splitting our code into so many horizontal layers, we will not have much mental capacity left for more important things. Important things like vertical slices, isolation, cohesion and so on.

Layers of abstractions aren't cheap, we should not add them blindly just everywhere.

If I need some truly infrastructure-independent business logic, no problem, I will use DIP. But I won't split my logic into "domain" or "business logic" layers, because it may confuse others. It is confusing me already, because those two layers you suggested (domain and business logic) for me are the same thing.

I won't name it "Onion Architecture" either. Because even between two of us there's a different understanding of this onion architecture. DIP turns out to be a much simpler and harder to misinterpret, whereas providing the exact same benefit.

zakirullin commented 1 year ago

https://github.com/zakirullin/cognitive-load/commit/cb424e1804e2f9fb1854968f415cb3d423d50e79 https://github.com/zakirullin/cognitive-load/commit/d1fe571a05356165f5e7c2f918b482d3dd22d290

zakirullin commented 5 months ago

https://github.com/zakirullin/cognitive-load/discussions/24