SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Onion / Clean Architecture
uh... ogres are like onions!
$whoami
• Attila Bertók
• C# technical lead
• Contact:
• bertok.atti@gmail.com
• https://www.linkedin.com/in/bertokattila/
What is an Onion Architecture like?
• Shrek: ... uh... ogres are like onions!
• [holds up an onion, which Donkey sniffs]
• Donkey: They stink?
• Shrek: Yes... No!
• Donkey: Oh, they make you cry?
• Shrek: No!
• Donkey: Oh, you leave 'em out in the sun, they get all brown, start sproutin' little white hairs...
• Shrek: [peels an onion] NO! Layers. Onions have layers. Ogres have layers... You get it? We both have layers.
• [walks off]
• Donkey: Oh, you both have LAYERS. Oh. You know, not everybody like onions. CAKE! Everybody loves cake! Cakes have
layers!
• Shrek: I don't care what everyone likes! Ogres are not like cakes.
Why do we even need
architecture?
What has the architectures ever given us?
Aspects that (used to) define a system
• Programming language
• Frameworks and Libraries
• Database
• UI
• Environment (desktop / web), “natural habitat”
• Delivery method
Which one would you like to live in? 
Which one would you like to live in? 
Screaming Architecture
• The blueprint of a church/library/hospital emphasizes different considerations that of
a family residence, as the “use cases“ are different. Considerations on implementation
detail (building material, color, etc.) should be secondary.
Architecture as Support Structure
• Architectures are structures that support the use cases of the system.
• A good software architecture is rather similar to a good blueprint: it concentrates on
the use cases, and lets minor decisions (what database engine to use? What
framework(s) to use? What programming language to use? Should web or desktop
environment be used?) be deferred.
• The architecture should clearly communicate the intent (the business domain)
• And not the implementation details (ASP, MVVM, Ruby on Rails)
• “Screaming architecture”
Postponing Decisions
• The best decision is a postponed decision.
• You might later learn certain facts that if you knew in advance might have made a
difference.
• It is possible that you might realize that what you thought necessary at a point in
development is not even required, so you can decide on not having a certain component at all.
• You are forced to make your dependencies modular (and it makes it easy to make them
testable).
• You are forced to depend on abstractions.
Paradigm Shift:
Implementation Agnostic Architecture
• Database is a detail
• GUI is a detail
• Programming language is a detail
• Delivery method is a detail
These details should be handled independently and arranged around the business logic.
Domain-Driven Design? / Behavior-Driven Development? / Acceptance-Test-Driven
Development?
SOLID Architecture
What?! SOLID again?!
Yes, SOLID again
• It does not only apply on class level, but on method level, or the other way around,
module/project level as well
• Or at least some rather similar principles do apply
• At least most of the principles can be scaled up to modules in a sensible way
SOLID
• Single Responsibility Principle – Separation of Concerns:
one module should have one reason to change
• Common Closure Principle:
• Those classes that change for the same reasons and at the same times should be gathered into one
component. Those classes that change for different reasons and at different times should be separated
into different components.
• Connected to the Open/Closed principle as well: components are closed to some changes
SOLID
• Liskov Substitution Principle
• Let’s skip discussing this one, does not have serious architectural implications.
SOLID
• Interface Segregation Principle:
don’t create dependency on components you don’t need
• Common Reuse Principle:
• Don’t depend on classes you don’t need.
• “Component-segregation”
• If some classes depend on a component, they should depend on all of said component (or at least on an
a significant portion of said component). Independent parts mean that the original component can be
separated to smaller components.
SOLID
• Inversion of Dependencies – Loose Coupling:
modules should be easy to be swapped or modified, independently of each other
• Stable Dependencies Principle:
• Depend in the direction of Stability.
• I = R| / (R| + R|)
• Don’t depend on components that are more instable.
• Stable Abstractions Principle:
• A component should be as abstract as it is stable.
• A = Nac / Nc
• SDP + SAP = DIP in the component-world: “Depend in the direction of abstraction”
Depend in the direction of
abstraction
Layers
Layers everywhere
A classical architecture-diagram
• Layers are… well, “layered”, from bottom to top
• References point downwards, from the top to the bottom, layers are only allowed to
reference layers directly beneath themselves.
Layers (3-tier)
Database Access
Business Logic
Client / UI
Problems of the classic n-tier solution
• Visualization concerns:
• A lot of boxes with complex dependencies might not be easy to visualize
• There are boxes that intersect layers (cross-cutting concerns)
• These are mostly visualized as high, standing columns, and are usually called “Framework” or
“Infrastructure”
• A more practical concern:
• Strong coupling: “boxes” have some assumptions about each other, generally about boxes
they have beneath them (we generally have assumptions towards the DAL – even from the
level of the UI (they might be transitive dependencies, and not direct ones, still, they are
dependencies))
A more complex architecture diagram
The Onion
• At first glance, it seems to be just a fancy way of visualizing a complex N-tier
architecture
• The visualization is more favorable as low layers generally contain only small
amounts of code, in a small amount of modules – thus drawing only a few big boxes
would be misleading
• What the onion does is it wraps the box diagram around, using a pie diagram instead
• Whatever was on the bottom is now on the inside
3-tier, in an almost-onion format
Client / UI
Business Logic
Data access
Onion layer-diagram
• Layers are built on each other from the inside to the outside
• The Dependency Rule: References are pointing inward, layers can only reference
layers beneath their own level, but they can reference other layers any level beneath
themselves.
• There are interfaces defined between the layers
• These interfaces physically belong to the more central layer.
• Modules in the same layer know nothing about each other, they are not connected
directly. Their only knowledge about each other comes through interfaces from lower
layers and DI. (And some sort of Pub/Sub messaging.)
So, all I need to do…
Is to start with this… And create this, right?
Wrong!
There is more to the Onion than the visuals:
Or, to put it another way…
Layered, represented as Quasi-Onion Actual Onion
A more valid onion-diagram
EBI
Entities, Boundaries, Interactors
Entities
• Entities represent business objects
• that have application independent business rules.
• They could be
• Books in a library
• Employees in an employee registry.
• All the application agnostic business rules should be located in the entities.
Boundaries
• Boundaries (seams) are the link to the outside world.
• Boundaries are functional: they accept data requests and produce responses as result.
• A boundary can define functionality for processing data for a graphical user interface
or a web API.
• These abstractions are concretely implemented by interactors.
Interactors
• Interactors are the business logic layer of the application.
• They accept requests through the boundaries and manipulate entities (application
state).
• They know of request and response models.
• Interactors are concrete implementations of boundaries.
EBI
Interactor
Entity
Response
Model
Controller
Presenter
ViewModel
View
Entity
Gateway
DB API
Entity
Entity
Request
Model
Request
Boundary
I
Response
Boundary
I
Entity
Gateway
Boudary
I
Layers
• Core (Policies – the most general and high level rules)
• Domain Entity Interfaces (Domain Entity Boundary)
• Domain Entities
• Data Access Interfaces (Data Access Boundary)
• Business Logic Interfaces (Service Interfaces – Use Case Boundary)
• Services (Use Cases)
• Application Services (Business Logic – Interactors)
• Interface Adapters / Infrastructure (Mechanisms)
• Data access (Repositories, Data mappers)
• Common infrastructure / Utility (aspects – Dependency injection, logging, file I/O, etc.)
Core
• Domain Entity Interfaces: (IUser)
• Domain Entities: implementation(s) to the above entities (User, Administrator)
• Data Access Interfaces: interfaces for domain entity repositories (IUserRepository).
Beware: implementations are not part of this layer! Remember the Dependency
Inversion Principle: “Abstractions should not depend on details. Details should
depend on abstractions.” Data access is a detail, we should not create a dependency
on it.
• Business Logic Interfaces: interfaces for business logic interactors
Services
• Business logic. No surprises here, interactors are implemented here.
Application Service Interfaces / Interface Adapters
• Data Access: Implementation of Data Access Interfaces project from the Core layer.
• Common Infrastructure / Utilities: Infrastructural details, such as DI, logging, etc.
• UI
Depend in the Direction of Stability
• The Core is stable! (It is generally not modified frequently)
• The Core has very abstract components (Boundaries!)
• Depending on the Core is depending in the direction of stability and abstraction.
• The Services / Use Cases layer is sort of stable, frequently extended, rarely modified
(Open/Closed Principle)
• The Application Service Interfaces depend (implement) the interfaces (boundaries)
from the inner layers (they depend in the direction of stability and abstraction).
Summary
• Dependency rule: you can reference inner layers only
• References can reach multiple layers inside
• The innermost layer (Core) contains Entities and Interfaces to outer layers
• Other inner layers (Use Cases) contain Interactors (Business Rules)
• Data Access (as a detail) is not part of the Core, it is instead part of the outermost
layer
• Were this an n-tier diagram, this would be the top layer, not the bottom!
• The GUI (as a detail) is also a part of the outermost layer
• Frameworks and other infrastructure (as details) are part of the outermost layer
• Tests are also part of the outermost layer
A tiny bit of history, please?
• Jeffery Palermo, 2008
• MVP, asp.net book author / co-author
• Onion Architecture was born as an extension of Model-View-Controller
• http://jeffreypalermo.com/blog/the-onion-architecture-part-1/
• Robert Cecil Martin, 2011
• Development Evangelist, Clean Code Advocate, God
• https://8thlight.com/blog/uncle-bob/2011/09/30/Screaming-Architecture.html
• https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html
• https://www.youtube.com/watch?v=Nsjsiz2A9mg
Q&A
Why is our product not structured like this is not allowed. 
Thank you!

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID PrinciplesGanesh Samarthyam
 
Project onion - Project Architecture for .Net Core Application
Project onion - Project Architecture for .Net Core ApplicationProject onion - Project Architecture for .Net Core Application
Project onion - Project Architecture for .Net Core ApplicationAbhinav Jha
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectJadson Santos
 
12 factor app an introduction
12 factor app an introduction12 factor app an introduction
12 factor app an introductionKrishna-Kumar
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the DomainVictor Rentea
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureMohamed Galal
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design PrinciplesAndreas Enbohm
 
Onion Architecture
Onion ArchitectureOnion Architecture
Onion Architecturematthidinger
 
Hexagonal architecture for java applications
Hexagonal architecture for java applicationsHexagonal architecture for java applications
Hexagonal architecture for java applicationsFabricio Epaminondas
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignYoung-Ho Cho
 
Clean Architecture Applications in Python
Clean Architecture Applications in PythonClean Architecture Applications in Python
Clean Architecture Applications in PythonSubhash Bhushan
 
Clean architecture
Clean architectureClean architecture
Clean architectureLieven Doclo
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to DockerAditya Konarde
 
Domain Driven Design: Zero to Hero
Domain Driven Design: Zero to HeroDomain Driven Design: Zero to Hero
Domain Driven Design: Zero to HeroFabrício Rissetto
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 

Was ist angesagt? (20)

Clean architecture
Clean architectureClean architecture
Clean architecture
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID Principles
 
Project onion - Project Architecture for .Net Core Application
Project onion - Project Architecture for .Net Core ApplicationProject onion - Project Architecture for .Net Core Application
Project onion - Project Architecture for .Net Core Application
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
12 factor app an introduction
12 factor app an introduction12 factor app an introduction
12 factor app an introduction
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the Domain
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
Introduction to DDD
Introduction to DDDIntroduction to DDD
Introduction to DDD
 
Onion Architecture
Onion ArchitectureOnion Architecture
Onion Architecture
 
Onion (clean) architecture
Onion (clean) architectureOnion (clean) architecture
Onion (clean) architecture
 
Hexagonal architecture for java applications
Hexagonal architecture for java applicationsHexagonal architecture for java applications
Hexagonal architecture for java applications
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Clean Architecture Applications in Python
Clean Architecture Applications in PythonClean Architecture Applications in Python
Clean Architecture Applications in Python
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Domain Driven Design: Zero to Hero
Domain Driven Design: Zero to HeroDomain Driven Design: Zero to Hero
Domain Driven Design: Zero to Hero
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 

Ähnlich wie Onion Architecture / Clean Architecture

Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock Steve Barbour
 
OOP -interface and objects.pptx
OOP -interface and objects.pptxOOP -interface and objects.pptx
OOP -interface and objects.pptxEdFeranil
 
Resilient Functional Service Design
Resilient Functional Service DesignResilient Functional Service Design
Resilient Functional Service DesignUwe Friedrichsen
 
Entity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and BeyondEntity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and BeyondSteve Westgarth
 
Service Architectures at Scale
Service Architectures at ScaleService Architectures at Scale
Service Architectures at ScaleRandy Shoup
 
The "Why", "What" and "How" of Microservices
The "Why", "What" and "How" of Microservices The "Why", "What" and "How" of Microservices
The "Why", "What" and "How" of Microservices INPAY
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Codersebbe
 
A Note on Distributed Computing - Papers We Love Hyderabad
A Note on Distributed Computing - Papers We Love HyderabadA Note on Distributed Computing - Papers We Love Hyderabad
A Note on Distributed Computing - Papers We Love HyderabadHrishikesh Barua
 
Deep Dive into the Idea of Software Architecture
Deep Dive into the Idea of Software ArchitectureDeep Dive into the Idea of Software Architecture
Deep Dive into the Idea of Software ArchitectureMatthew Clarke
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Hannes Lowette
 
DDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan PaulovichDDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan PaulovichIvan Paulovich
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)Tom Kocjan
 
10 Hinweise für Architekten
10 Hinweise für Architekten10 Hinweise für Architekten
10 Hinweise für Architektenadesso AG
 
Ten Advices for Architects
Ten Advices for ArchitectsTen Advices for Architects
Ten Advices for ArchitectsEberhard Wolff
 
2009 training - tim m - object oriented programming
2009   training - tim m - object oriented programming2009   training - tim m - object oriented programming
2009 training - tim m - object oriented programmingTim Mahy
 
Architecture - December 2013 - Avinash Ramineni, Shekhar Veumuri
Architecture   - December 2013 - Avinash Ramineni, Shekhar VeumuriArchitecture   - December 2013 - Avinash Ramineni, Shekhar Veumuri
Architecture - December 2013 - Avinash Ramineni, Shekhar Veumuriclairvoyantllc
 
Software Architecture and Architectors: useless VS valuable
Software Architecture and Architectors: useless VS valuableSoftware Architecture and Architectors: useless VS valuable
Software Architecture and Architectors: useless VS valuableComsysto Reply GmbH
 
Architectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and ConsistentlyArchitectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and ConsistentlyComsysto Reply GmbH
 
Architectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and ConsistentlyArchitectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and ConsistentlyComsysto Reply GmbH
 

Ähnlich wie Onion Architecture / Clean Architecture (20)

Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock
 
OOP -interface and objects.pptx
OOP -interface and objects.pptxOOP -interface and objects.pptx
OOP -interface and objects.pptx
 
Resilient Functional Service Design
Resilient Functional Service DesignResilient Functional Service Design
Resilient Functional Service Design
 
Entity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and BeyondEntity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and Beyond
 
Service Architectures at Scale
Service Architectures at ScaleService Architectures at Scale
Service Architectures at Scale
 
The "Why", "What" and "How" of Microservices
The "Why", "What" and "How" of Microservices The "Why", "What" and "How" of Microservices
The "Why", "What" and "How" of Microservices
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
A Note on Distributed Computing - Papers We Love Hyderabad
A Note on Distributed Computing - Papers We Love HyderabadA Note on Distributed Computing - Papers We Love Hyderabad
A Note on Distributed Computing - Papers We Love Hyderabad
 
Deep Dive into the Idea of Software Architecture
Deep Dive into the Idea of Software ArchitectureDeep Dive into the Idea of Software Architecture
Deep Dive into the Idea of Software Architecture
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
 
DDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan PaulovichDDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan Paulovich
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
 
10 Hinweise für Architekten
10 Hinweise für Architekten10 Hinweise für Architekten
10 Hinweise für Architekten
 
Ten Advices for Architects
Ten Advices for ArchitectsTen Advices for Architects
Ten Advices for Architects
 
2009 training - tim m - object oriented programming
2009   training - tim m - object oriented programming2009   training - tim m - object oriented programming
2009 training - tim m - object oriented programming
 
Architecture - December 2013 - Avinash Ramineni, Shekhar Veumuri
Architecture   - December 2013 - Avinash Ramineni, Shekhar VeumuriArchitecture   - December 2013 - Avinash Ramineni, Shekhar Veumuri
Architecture - December 2013 - Avinash Ramineni, Shekhar Veumuri
 
Software Architecture and Architectors: useless VS valuable
Software Architecture and Architectors: useless VS valuableSoftware Architecture and Architectors: useless VS valuable
Software Architecture and Architectors: useless VS valuable
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
 
Architectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and ConsistentlyArchitectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and Consistently
 
Architectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and ConsistentlyArchitectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and Consistently
 

Kürzlich hochgeladen

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Onion Architecture / Clean Architecture

  • 1. Onion / Clean Architecture uh... ogres are like onions!
  • 2. $whoami • Attila Bertók • C# technical lead • Contact: • bertok.atti@gmail.com • https://www.linkedin.com/in/bertokattila/
  • 3. What is an Onion Architecture like? • Shrek: ... uh... ogres are like onions! • [holds up an onion, which Donkey sniffs] • Donkey: They stink? • Shrek: Yes... No! • Donkey: Oh, they make you cry? • Shrek: No! • Donkey: Oh, you leave 'em out in the sun, they get all brown, start sproutin' little white hairs... • Shrek: [peels an onion] NO! Layers. Onions have layers. Ogres have layers... You get it? We both have layers. • [walks off] • Donkey: Oh, you both have LAYERS. Oh. You know, not everybody like onions. CAKE! Everybody loves cake! Cakes have layers! • Shrek: I don't care what everyone likes! Ogres are not like cakes.
  • 4. Why do we even need architecture? What has the architectures ever given us?
  • 5. Aspects that (used to) define a system • Programming language • Frameworks and Libraries • Database • UI • Environment (desktop / web), “natural habitat” • Delivery method
  • 6. Which one would you like to live in? 
  • 7. Which one would you like to live in? 
  • 8. Screaming Architecture • The blueprint of a church/library/hospital emphasizes different considerations that of a family residence, as the “use cases“ are different. Considerations on implementation detail (building material, color, etc.) should be secondary.
  • 9. Architecture as Support Structure • Architectures are structures that support the use cases of the system. • A good software architecture is rather similar to a good blueprint: it concentrates on the use cases, and lets minor decisions (what database engine to use? What framework(s) to use? What programming language to use? Should web or desktop environment be used?) be deferred. • The architecture should clearly communicate the intent (the business domain) • And not the implementation details (ASP, MVVM, Ruby on Rails) • “Screaming architecture”
  • 10. Postponing Decisions • The best decision is a postponed decision. • You might later learn certain facts that if you knew in advance might have made a difference. • It is possible that you might realize that what you thought necessary at a point in development is not even required, so you can decide on not having a certain component at all. • You are forced to make your dependencies modular (and it makes it easy to make them testable). • You are forced to depend on abstractions.
  • 11. Paradigm Shift: Implementation Agnostic Architecture • Database is a detail • GUI is a detail • Programming language is a detail • Delivery method is a detail These details should be handled independently and arranged around the business logic. Domain-Driven Design? / Behavior-Driven Development? / Acceptance-Test-Driven Development?
  • 13. Yes, SOLID again • It does not only apply on class level, but on method level, or the other way around, module/project level as well • Or at least some rather similar principles do apply • At least most of the principles can be scaled up to modules in a sensible way
  • 14. SOLID • Single Responsibility Principle – Separation of Concerns: one module should have one reason to change • Common Closure Principle: • Those classes that change for the same reasons and at the same times should be gathered into one component. Those classes that change for different reasons and at different times should be separated into different components. • Connected to the Open/Closed principle as well: components are closed to some changes
  • 15. SOLID • Liskov Substitution Principle • Let’s skip discussing this one, does not have serious architectural implications.
  • 16. SOLID • Interface Segregation Principle: don’t create dependency on components you don’t need • Common Reuse Principle: • Don’t depend on classes you don’t need. • “Component-segregation” • If some classes depend on a component, they should depend on all of said component (or at least on an a significant portion of said component). Independent parts mean that the original component can be separated to smaller components.
  • 17. SOLID • Inversion of Dependencies – Loose Coupling: modules should be easy to be swapped or modified, independently of each other • Stable Dependencies Principle: • Depend in the direction of Stability. • I = R| / (R| + R|) • Don’t depend on components that are more instable. • Stable Abstractions Principle: • A component should be as abstract as it is stable. • A = Nac / Nc • SDP + SAP = DIP in the component-world: “Depend in the direction of abstraction”
  • 18. Depend in the direction of abstraction
  • 20. A classical architecture-diagram • Layers are… well, “layered”, from bottom to top • References point downwards, from the top to the bottom, layers are only allowed to reference layers directly beneath themselves.
  • 22. Problems of the classic n-tier solution • Visualization concerns: • A lot of boxes with complex dependencies might not be easy to visualize • There are boxes that intersect layers (cross-cutting concerns) • These are mostly visualized as high, standing columns, and are usually called “Framework” or “Infrastructure” • A more practical concern: • Strong coupling: “boxes” have some assumptions about each other, generally about boxes they have beneath them (we generally have assumptions towards the DAL – even from the level of the UI (they might be transitive dependencies, and not direct ones, still, they are dependencies))
  • 23. A more complex architecture diagram
  • 24. The Onion • At first glance, it seems to be just a fancy way of visualizing a complex N-tier architecture • The visualization is more favorable as low layers generally contain only small amounts of code, in a small amount of modules – thus drawing only a few big boxes would be misleading • What the onion does is it wraps the box diagram around, using a pie diagram instead • Whatever was on the bottom is now on the inside
  • 25. 3-tier, in an almost-onion format Client / UI Business Logic Data access
  • 26. Onion layer-diagram • Layers are built on each other from the inside to the outside • The Dependency Rule: References are pointing inward, layers can only reference layers beneath their own level, but they can reference other layers any level beneath themselves. • There are interfaces defined between the layers • These interfaces physically belong to the more central layer. • Modules in the same layer know nothing about each other, they are not connected directly. Their only knowledge about each other comes through interfaces from lower layers and DI. (And some sort of Pub/Sub messaging.)
  • 27. So, all I need to do… Is to start with this… And create this, right?
  • 29. There is more to the Onion than the visuals:
  • 30. Or, to put it another way… Layered, represented as Quasi-Onion Actual Onion
  • 31. A more valid onion-diagram
  • 33. Entities • Entities represent business objects • that have application independent business rules. • They could be • Books in a library • Employees in an employee registry. • All the application agnostic business rules should be located in the entities.
  • 34. Boundaries • Boundaries (seams) are the link to the outside world. • Boundaries are functional: they accept data requests and produce responses as result. • A boundary can define functionality for processing data for a graphical user interface or a web API. • These abstractions are concretely implemented by interactors.
  • 35. Interactors • Interactors are the business logic layer of the application. • They accept requests through the boundaries and manipulate entities (application state). • They know of request and response models. • Interactors are concrete implementations of boundaries.
  • 37. Layers • Core (Policies – the most general and high level rules) • Domain Entity Interfaces (Domain Entity Boundary) • Domain Entities • Data Access Interfaces (Data Access Boundary) • Business Logic Interfaces (Service Interfaces – Use Case Boundary) • Services (Use Cases) • Application Services (Business Logic – Interactors) • Interface Adapters / Infrastructure (Mechanisms) • Data access (Repositories, Data mappers) • Common infrastructure / Utility (aspects – Dependency injection, logging, file I/O, etc.)
  • 38. Core • Domain Entity Interfaces: (IUser) • Domain Entities: implementation(s) to the above entities (User, Administrator) • Data Access Interfaces: interfaces for domain entity repositories (IUserRepository). Beware: implementations are not part of this layer! Remember the Dependency Inversion Principle: “Abstractions should not depend on details. Details should depend on abstractions.” Data access is a detail, we should not create a dependency on it. • Business Logic Interfaces: interfaces for business logic interactors
  • 39. Services • Business logic. No surprises here, interactors are implemented here.
  • 40. Application Service Interfaces / Interface Adapters • Data Access: Implementation of Data Access Interfaces project from the Core layer. • Common Infrastructure / Utilities: Infrastructural details, such as DI, logging, etc. • UI
  • 41. Depend in the Direction of Stability • The Core is stable! (It is generally not modified frequently) • The Core has very abstract components (Boundaries!) • Depending on the Core is depending in the direction of stability and abstraction. • The Services / Use Cases layer is sort of stable, frequently extended, rarely modified (Open/Closed Principle) • The Application Service Interfaces depend (implement) the interfaces (boundaries) from the inner layers (they depend in the direction of stability and abstraction).
  • 42. Summary • Dependency rule: you can reference inner layers only • References can reach multiple layers inside • The innermost layer (Core) contains Entities and Interfaces to outer layers • Other inner layers (Use Cases) contain Interactors (Business Rules) • Data Access (as a detail) is not part of the Core, it is instead part of the outermost layer • Were this an n-tier diagram, this would be the top layer, not the bottom! • The GUI (as a detail) is also a part of the outermost layer • Frameworks and other infrastructure (as details) are part of the outermost layer • Tests are also part of the outermost layer
  • 43. A tiny bit of history, please? • Jeffery Palermo, 2008 • MVP, asp.net book author / co-author • Onion Architecture was born as an extension of Model-View-Controller • http://jeffreypalermo.com/blog/the-onion-architecture-part-1/ • Robert Cecil Martin, 2011 • Development Evangelist, Clean Code Advocate, God • https://8thlight.com/blog/uncle-bob/2011/09/30/Screaming-Architecture.html • https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html • https://www.youtube.com/watch?v=Nsjsiz2A9mg
  • 44. Q&A Why is our product not structured like this is not allowed. 

Hinweis der Redaktion

  1. https://www.youtube.com/watch?v=_bMcXVe8zIs
  2. (A church and a library)
  3. (A hospital and a residential building)
  4. Following the control flow, we have an HTTP Request that reaches the Controller. The controller will then: Dismantle the Request; Create a Request Model with the relevant data; Execute a method in the Interactor (which was injected into the Controller using the Interactor’s interface, the Boundary), passing it the Request Model; The Interactor: Uses the Entity Gateway Implementation (which was injected into the Interactor using the Entity Gateway Interface) to find the relevant Entities; Orchestrates interactions between Entities; Creates a Response Model with the data result of the Operation; Populates the Presenter giving it the Response Model; Returns the Presenter to the Controller; Uses the Presenter to generate a ViewModel; Binds the ViewModel to the View; Returns the View to the client.