SlideShare a Scribd company logo
1 of 41
Download to read offline
2 VictorRentea.ro
a training by
= Software architecture refers to the fundamental structures of
a software system and the discipline of creating such structures and
systems. Each structure comprises software elements, relations
among them, and properties of both elements and relations.
3 VictorRentea.ro
a training by
= The Stuff That's Hard to Change Later
= The Art of Drawing Lines (boundaries)
= The Stuff That Matters
4 VictorRentea.ro
a training by
5 VictorRentea.ro
a training by
The Code - anonymous developer
Hi, I'm Victor Rentea
Java Champion – drinking since 2006
Trainer – 3000+ developers / 80+ companies, since 2013
Speaker – Conferences & Meetups
Hibernate
Spring Java8/FP
Java Performance Reactive Programming
Architecture Clean Code Unit Testing
Java Champion – drinking since 2006
Trainer – 3000+ developers / 80+ companies, since 2013
Speaker – Conferences & Meetups
Hibernate
Spring Java8/FP
$
Hibernate
Spring Java8/FP
Java Performance Reactive Programming
Architecture Clean Code Unit Testing
Masterclass
Company
Training
Video
Courses
Talks &
Channel
Join My
Communit
y
Blog
@victorrentea
VictorRentea.ro
victorrentea@gmail.com
8 VictorRentea.ro
a training by
Layers
SUB-DOMAINS
Controller
Service
Repository
APIs
order Product user
customer
Client
9 VictorRentea.ro
a training by
Axiom 1: Logic is simpler if implemented using data structures we control
10 VictorRentea.ro
a training by
Axiom 1: Logic is simpler if implemented using data structures we control
Smaller: only the 5 required fields, not all 20
OOP: with helper methods inside
Safer: null-safe, guarding invariants, immutable?
Extract Value Objects
Split Large Entities vs BC
Keep DTOs out
11 VictorRentea.ro
a training by
DTOs
are Evil
Chapter 1
13 VictorRentea.ro
a training by
Exposed APIs
To browsers To other systems Nanoservice
called by js,ng,jsx,...
14 VictorRentea.ro
a training by
Decouple API from Domain Model
Delete
“canBeDeletedByCurrentUser”: false
To browsers
“dateFormatted”: "1 Iunie 2021"
DTOs are controlled by Frontend
15 VictorRentea.ro
a training by
APIs
To browsers
DTOs are controlled by Frontend DTOs are negotiated
with clients
DTOs can be shared
within the same Bounded Context
Nanoservice
=XXS microservice
eg. 5 devs maintaining
20 microservices
Multiple FEs/mobile: GraphQL
To other systems
Bounded Context A
(TeamA)
Bounded Context B
(TeamB)
1
2
3
X
16 VictorRentea.ro
a training by
Decoupling
DTO
Domain
Model
< >
Price: more classes + mapping
Exception:
Boundary Systems
= Huge Adapters
without own Domain
Software Ecosystem
Generated DTOs:
JSON: .yaml ➔ swagger-gen
XML: .xsd/.wsdl ➔ xjc
17 VictorRentea.ro
a training by
Auto-Generated Mappers
eg. Entity  DTO
as long as the field names match,
mapping happens automatically
eg MapStruct
Temptation:
Keep the models in sync
Entities and DTOs should will diverge
18 VictorRentea.ro
a training by
domain
Value Object
Entity
id
Domain
Service
The code you want to protect:
stays in domain module!
Priceless Domain Logic
Domain Objects
What's specific
to your app
19 VictorRentea.ro
a training by
External
Service
domain
DTO
call
Domain
Service
20 VictorRentea.ro
a training by
External
Service
DTO
Adapter
Domain
Service
Domain
Service
<dependency>
domain infrastructure
Goal: Keep Your Precious Domain
isolated from external influences
may slip in
DTO
VictorRentea.ro
21
External
Service
DTO
IAdapter Adapter
implements
class UserApiClient
implements IUserAdapter {
public User getById(id){
<external call>
}
}
interface IUserAdapter {
User getById(id);
}
class OrderService {
@Autowired
IUserAdapter adapter;
...
adapter.getById(id);
}
express your need in
a domain interface…
and implement it in a
lower-level module…
When you need
to call outside…
so nothing foreign
enters your domain.
Domain
Service
Domain
Service
<dependency>
domain infrastructure
DTO
22 VictorRentea.ro
a training by
calls
Dependency Inversion Principle
<dependency>
higher-level
module
lower-level
module
"Best of OOP"
- Uncle Bob
Abstractions should not depend on details
Low level classes
are not visible
(SOLID Principles)
Dependency Inversion
23 VictorRentea.ro
a training by
calls
<dependency>
higher-level
module
lower-level
module RMI,
HTTP
GRPC..
FTP
Queue
DB
DTO
Dependency Inversion
24 VictorRentea.ro
a training by
Stop Code Dependencies
Dependency Inversion
Package Dependency Checks - by static code analysis
- by compiler
@Test
public void dependencyInversionTest() {
ArchRuleDefinition
.noClasses().that().resideInAPackage("..domain")
.should().dependOnClassesThat().resideInAPackage("..infra")
.check(new ClassFileImporter().importPackages("my.corp.app"));
}
testImplementation com.tngtech.archunit:archunit-junit4:0.15.0 or NDepend (C#)
https://nx.dev/latest/angular/structure/monorepo-tags
https://github.com/MaibornWolff/ts-arch
25 VictorRentea.ro
a training by
An Agnostic Domain
lets you focus on
YOUR logic
Agnostic Domain
27 VictorRentea.ro
a training by
infrastructure
EXTERNAL
API
Value Object
Entity
id
Domain
Service
IAdapter
Onion Architecture
Behold, the famous
Database
domain
Repo
Dep Inv
Dep Inv
DTO
Agnostic Domain
application
DTO
Your
Client
Validation
Separate
Persistence
Model
if DB == enemy
Façade
Mapper
Controller
Adapter
Spring Data
IRepo
28 VictorRentea.ro
a training by
28
DTO
Value Object
Entity
id
Domain
Service
application Database
domain
DTO
Onion Architecture
Pragmatic
Agnostic Domain
EXTERNAL
API
Your
Client
Façade
Mapper
Controller
Adapter
IAdapter
IRepo
Dep Inv
29 VictorRentea.ro
a training by
Independent of Intrusive Frameworks
Testable Standalone
without a DB, UI, Web Server, etc...
https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html
Independent of UI
mobile, web, or desktop
Independent of DB
avoid PL/SQL, no vendor lock-in
Independent of External APIs
= external Bounded Contexts
Is an ORM intrusive?
Keep core logic ...
Agnostic Domain
aka Hexagonal
aka Ports-and-Adapters
aka Clean Architecture
Onion Architecture
31 VictorRentea.ro
a training by
Keep Domain Object design
independent of persistence
Decompose large flat Entities with @Embeddable
Avoid useless IDs with @ElementCollection
Constructor constraints are possible, hiding default one
Question entity links. Aren't IDs enough?
Designing Expressive and Performant Persistence Models
https://www.youtube.com/watch?v=iw0tOx7Zbjc
Legacy DB Schema ➔ Separate Models
Mappers ➔ Pain
Avoid bi-directional links
32 VictorRentea.ro
a training by
Axiom 1: Logic is simpler if implemented using data structures we control
Smaller: only the 5 required fields, not all 20
OOP: with helper methods inside
Safer: null-safe, guarding invariants, immutable?
Extract Value Objects
Split Large Entities vs BC
Keep DTOs out
33 VictorRentea.ro
a training by
Extract Value Objects
from Entities
Chapter 2
34 VictorRentea.ro
a training by
How many fields it has?
Can you make it immutable?
Tell me about that big entity ...
How do you feel about moving logic inside?
35 VictorRentea.ro
a training by
How many fields it has?
Can you make it immutable?
How do you feel about moving logic inside?
Yes!
(use @Embeddable for JPA)
But, How to identify Value Objects?
Extract Value Objects from Entities:
36 VictorRentea.ro
a training by
Conceptual Whole
Money {amount, currency}
Changes Together
LastModifiedBy/Time
How to identify Value Objects?
Screens
InvoicingDetails
Moves Together
PriceComputationInput
37 VictorRentea.ro
a training by
Chapter 3
The Confused Entity
38 VictorRentea.ro
a training by
What's bad with Legacy Code?
Old-style, -frameworks
Massive Unknown Code
Excessive Coupling
39 VictorRentea.ro
a training by
40 VictorRentea.ro
a training by
Order
Product
«entity»
Product
40 fields
«entity»
Product
15 fields
«entity»
Product
30 fields
41 VictorRentea.ro
a training by
Order
Product
«entity»
Product
15 fields
«entity»
Product
30 fields
42 VictorRentea.ro
a training by
Axiom 1: Logic is simpler if implemented using data structures we control
Smaller: only the 5 required fields, not all 20
OOP: with helper methods inside
Safer: null-safe, guarding invariants, immutable?
Extract Value Objects
Split Large Entities vs BC
Keep DTOs out
Axiom 1: Logic is simpler if implemented using data structures we control
Clean Architecture
Thank you!
victorrentea@gmail.com VictorRentea.ro @victorrentea

More Related Content

What's hot

Clean Architecture
Clean ArchitectureClean Architecture
Clean ArchitectureFlavius Stef
 
The Art of Clean code
The Art of Clean codeThe Art of Clean code
The Art of Clean codeVictor Rentea
 
Clean architecture: Android
Clean architecture: AndroidClean architecture: Android
Clean architecture: Androidintive
 
Software Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdfSoftware Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdfVictor Rentea
 
Integration testing with spring @snow one
Integration testing with spring @snow oneIntegration testing with spring @snow one
Integration testing with spring @snow oneVictor Rentea
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean ArchitectureMattia Battiston
 
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's GuideEvolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's GuideVictor Rentea
 
Functional Patterns with Java8 @Bucharest Java User Group
Functional Patterns with Java8 @Bucharest Java User GroupFunctional Patterns with Java8 @Bucharest Java User Group
Functional Patterns with Java8 @Bucharest Java User GroupVictor Rentea
 
Clean architecture
Clean architectureClean architecture
Clean architectureandbed
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software designMatthias Noback
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignVictor Rentea
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionsaber tabatabaee
 
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Victor Rentea
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidOutware Mobile
 
Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Victor Rentea
 
Hexagonal architecture for java applications
Hexagonal architecture for java applicationsHexagonal architecture for java applications
Hexagonal architecture for java applicationsFabricio Epaminondas
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureMohamed Galal
 

What's hot (20)

Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
The Art of Clean code
The Art of Clean codeThe Art of Clean code
The Art of Clean code
 
Clean architecture: Android
Clean architecture: AndroidClean architecture: Android
Clean architecture: Android
 
Software Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdfSoftware Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdf
 
Integration testing with spring @snow one
Integration testing with spring @snow oneIntegration testing with spring @snow one
Integration testing with spring @snow one
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean Architecture
 
Clean code
Clean code Clean code
Clean code
 
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's GuideEvolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
 
Functional Patterns with Java8 @Bucharest Java User Group
Functional Patterns with Java8 @Bucharest Java User GroupFunctional Patterns with Java8 @Bucharest Java User Group
Functional Patterns with Java8 @Bucharest Java User Group
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software design
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
 
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
 
Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8
 
Clean Code
Clean CodeClean Code
Clean Code
 
Hexagonal architecture for java applications
Hexagonal architecture for java applicationsHexagonal architecture for java applications
Hexagonal architecture for java applications
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
 

Similar to Clean architecture - Protecting the Domain

The tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptxThe tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptxVictor Rentea
 
Vertical Slicing Architectures
Vertical Slicing ArchitecturesVertical Slicing Architectures
Vertical Slicing ArchitecturesVictor Rentea
 
Test-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxTest-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxVictor Rentea
 
Java Programming
Java ProgrammingJava Programming
Java ProgrammingTracy Clark
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2Enea Gabriel
 
Framework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users GroupFramework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users Groupbrada
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Luis Valencia
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxdanhaley45372
 
Mihai Tataran - Building Windows 8 Applications with HTML5 and JS
Mihai Tataran - Building Windows 8 Applications with HTML5 and JSMihai Tataran - Building Windows 8 Applications with HTML5 and JS
Mihai Tataran - Building Windows 8 Applications with HTML5 and JSITCamp
 
How to Create Blockchain Products by Fr8 Network Lead Engineer
How to Create Blockchain Products by Fr8 Network Lead EngineerHow to Create Blockchain Products by Fr8 Network Lead Engineer
How to Create Blockchain Products by Fr8 Network Lead EngineerProduct School
 
Top 50 .NET Interview Questions and Answers 2019 | Edureka
Top 50 .NET Interview Questions and Answers 2019 | EdurekaTop 50 .NET Interview Questions and Answers 2019 | Edureka
Top 50 .NET Interview Questions and Answers 2019 | EdurekaEdureka!
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstEnea Gabriel
 
Mocking vtcc3 - en
Mocking   vtcc3 - enMocking   vtcc3 - en
Mocking vtcc3 - envgrondin
 
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsVolodymyr Voytyshyn
 
.NET Attributes and Reflection - What a Developer Needs to Know...
.NET Attributes and Reflection - What a Developer Needs to Know....NET Attributes and Reflection - What a Developer Needs to Know...
.NET Attributes and Reflection - What a Developer Needs to Know...Dan Douglas
 

Similar to Clean architecture - Protecting the Domain (20)

The tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptxThe tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptx
 
Vertical Slicing Architectures
Vertical Slicing ArchitecturesVertical Slicing Architectures
Vertical Slicing Architectures
 
Test-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxTest-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptx
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
 
Game Studio
Game StudioGame Studio
Game Studio
 
Framework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users GroupFramework Design Guidelines For Brussels Users Group
Framework Design Guidelines For Brussels Users Group
 
Eugene Burmako
Eugene BurmakoEugene Burmako
Eugene Burmako
 
Effective Java
Effective JavaEffective Java
Effective Java
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Mihai Tataran - Building Windows 8 Applications with HTML5 and JS
Mihai Tataran - Building Windows 8 Applications with HTML5 and JSMihai Tataran - Building Windows 8 Applications with HTML5 and JS
Mihai Tataran - Building Windows 8 Applications with HTML5 and JS
 
How to Create Blockchain Products by Fr8 Network Lead Engineer
How to Create Blockchain Products by Fr8 Network Lead EngineerHow to Create Blockchain Products by Fr8 Network Lead Engineer
How to Create Blockchain Products by Fr8 Network Lead Engineer
 
Top 50 .NET Interview Questions and Answers 2019 | Edureka
Top 50 .NET Interview Questions and Answers 2019 | EdurekaTop 50 .NET Interview Questions and Answers 2019 | Edureka
Top 50 .NET Interview Questions and Answers 2019 | Edureka
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
Mocking vtcc3 - en
Mocking   vtcc3 - enMocking   vtcc3 - en
Mocking vtcc3 - en
 
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design Patterns
 
Mini-Training: Javascript Patterns
Mini-Training: Javascript PatternsMini-Training: Javascript Patterns
Mini-Training: Javascript Patterns
 
.NET Attributes and Reflection - What a Developer Needs to Know...
.NET Attributes and Reflection - What a Developer Needs to Know....NET Attributes and Reflection - What a Developer Needs to Know...
.NET Attributes and Reflection - What a Developer Needs to Know...
 

More from Victor Rentea

Microservice Resilience Patterns @VoxxedCern'24
Microservice Resilience Patterns @VoxxedCern'24Microservice Resilience Patterns @VoxxedCern'24
Microservice Resilience Patterns @VoxxedCern'24Victor Rentea
 
Distributed Consistency.pdf
Distributed Consistency.pdfDistributed Consistency.pdf
Distributed Consistency.pdfVictor Rentea
 
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteClean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteVictor Rentea
 
Testing Microservices @DevoxxBE 23.pdf
Testing Microservices @DevoxxBE 23.pdfTesting Microservices @DevoxxBE 23.pdf
Testing Microservices @DevoxxBE 23.pdfVictor Rentea
 
From Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptxFrom Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptxVictor Rentea
 
Profiling your Java Application
Profiling your Java ApplicationProfiling your Java Application
Profiling your Java ApplicationVictor Rentea
 
Unit testing - 9 design hints
Unit testing - 9 design hintsUnit testing - 9 design hints
Unit testing - 9 design hintsVictor Rentea
 
Extreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipExtreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipVictor Rentea
 
Refactoring blockers and code smells @jNation 2021
Refactoring   blockers and code smells @jNation 2021Refactoring   blockers and code smells @jNation 2021
Refactoring blockers and code smells @jNation 2021Victor Rentea
 
Hibernate and Spring - Unleash the Magic
Hibernate and Spring - Unleash the MagicHibernate and Spring - Unleash the Magic
Hibernate and Spring - Unleash the MagicVictor Rentea
 
Integration testing with spring @JAX Mainz
Integration testing with spring @JAX MainzIntegration testing with spring @JAX Mainz
Integration testing with spring @JAX MainzVictor Rentea
 
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021Victor Rentea
 
Pure functions and immutable objects @dev nexus 2021
Pure functions and immutable objects @dev nexus 2021Pure functions and immutable objects @dev nexus 2021
Pure functions and immutable objects @dev nexus 2021Victor Rentea
 
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...Victor Rentea
 
Pure Functions and Immutable Objects
Pure Functions and Immutable ObjectsPure Functions and Immutable Objects
Pure Functions and Immutable ObjectsVictor Rentea
 
Definitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in JavaDefinitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in JavaVictor Rentea
 
Extreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipExtreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipVictor Rentea
 
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...Victor Rentea
 

More from Victor Rentea (20)

Microservice Resilience Patterns @VoxxedCern'24
Microservice Resilience Patterns @VoxxedCern'24Microservice Resilience Patterns @VoxxedCern'24
Microservice Resilience Patterns @VoxxedCern'24
 
Distributed Consistency.pdf
Distributed Consistency.pdfDistributed Consistency.pdf
Distributed Consistency.pdf
 
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteClean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
 
Testing Microservices @DevoxxBE 23.pdf
Testing Microservices @DevoxxBE 23.pdfTesting Microservices @DevoxxBE 23.pdf
Testing Microservices @DevoxxBE 23.pdf
 
From Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptxFrom Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptx
 
Profiling your Java Application
Profiling your Java ApplicationProfiling your Java Application
Profiling your Java Application
 
OAuth in the Wild
OAuth in the WildOAuth in the Wild
OAuth in the Wild
 
Unit testing - 9 design hints
Unit testing - 9 design hintsUnit testing - 9 design hints
Unit testing - 9 design hints
 
Extreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipExtreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software Craftsmanship
 
Refactoring blockers and code smells @jNation 2021
Refactoring   blockers and code smells @jNation 2021Refactoring   blockers and code smells @jNation 2021
Refactoring blockers and code smells @jNation 2021
 
Hibernate and Spring - Unleash the Magic
Hibernate and Spring - Unleash the MagicHibernate and Spring - Unleash the Magic
Hibernate and Spring - Unleash the Magic
 
Integration testing with spring @JAX Mainz
Integration testing with spring @JAX MainzIntegration testing with spring @JAX Mainz
Integration testing with spring @JAX Mainz
 
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
 
Pure functions and immutable objects @dev nexus 2021
Pure functions and immutable objects @dev nexus 2021Pure functions and immutable objects @dev nexus 2021
Pure functions and immutable objects @dev nexus 2021
 
TDD Mantra
TDD MantraTDD Mantra
TDD Mantra
 
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
 
Pure Functions and Immutable Objects
Pure Functions and Immutable ObjectsPure Functions and Immutable Objects
Pure Functions and Immutable Objects
 
Definitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in JavaDefinitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in Java
 
Extreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipExtreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software Craftsmanship
 
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
 

Recently uploaded

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Recently uploaded (20)

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

Clean architecture - Protecting the Domain

  • 1.
  • 2. 2 VictorRentea.ro a training by = Software architecture refers to the fundamental structures of a software system and the discipline of creating such structures and systems. Each structure comprises software elements, relations among them, and properties of both elements and relations.
  • 3. 3 VictorRentea.ro a training by = The Stuff That's Hard to Change Later = The Art of Drawing Lines (boundaries) = The Stuff That Matters
  • 5. 5 VictorRentea.ro a training by The Code - anonymous developer
  • 6. Hi, I'm Victor Rentea Java Champion – drinking since 2006 Trainer – 3000+ developers / 80+ companies, since 2013 Speaker – Conferences & Meetups Hibernate Spring Java8/FP Java Performance Reactive Programming Architecture Clean Code Unit Testing Java Champion – drinking since 2006 Trainer – 3000+ developers / 80+ companies, since 2013 Speaker – Conferences & Meetups Hibernate Spring Java8/FP
  • 7. $ Hibernate Spring Java8/FP Java Performance Reactive Programming Architecture Clean Code Unit Testing Masterclass Company Training Video Courses Talks & Channel Join My Communit y Blog @victorrentea VictorRentea.ro victorrentea@gmail.com
  • 8. 8 VictorRentea.ro a training by Layers SUB-DOMAINS Controller Service Repository APIs order Product user customer Client
  • 9. 9 VictorRentea.ro a training by Axiom 1: Logic is simpler if implemented using data structures we control
  • 10. 10 VictorRentea.ro a training by Axiom 1: Logic is simpler if implemented using data structures we control Smaller: only the 5 required fields, not all 20 OOP: with helper methods inside Safer: null-safe, guarding invariants, immutable? Extract Value Objects Split Large Entities vs BC Keep DTOs out
  • 11. 11 VictorRentea.ro a training by DTOs are Evil Chapter 1
  • 12.
  • 13. 13 VictorRentea.ro a training by Exposed APIs To browsers To other systems Nanoservice called by js,ng,jsx,...
  • 14. 14 VictorRentea.ro a training by Decouple API from Domain Model Delete “canBeDeletedByCurrentUser”: false To browsers “dateFormatted”: "1 Iunie 2021" DTOs are controlled by Frontend
  • 15. 15 VictorRentea.ro a training by APIs To browsers DTOs are controlled by Frontend DTOs are negotiated with clients DTOs can be shared within the same Bounded Context Nanoservice =XXS microservice eg. 5 devs maintaining 20 microservices Multiple FEs/mobile: GraphQL To other systems Bounded Context A (TeamA) Bounded Context B (TeamB) 1 2 3 X
  • 16. 16 VictorRentea.ro a training by Decoupling DTO Domain Model < > Price: more classes + mapping Exception: Boundary Systems = Huge Adapters without own Domain Software Ecosystem Generated DTOs: JSON: .yaml ➔ swagger-gen XML: .xsd/.wsdl ➔ xjc
  • 17. 17 VictorRentea.ro a training by Auto-Generated Mappers eg. Entity  DTO as long as the field names match, mapping happens automatically eg MapStruct Temptation: Keep the models in sync Entities and DTOs should will diverge
  • 18. 18 VictorRentea.ro a training by domain Value Object Entity id Domain Service The code you want to protect: stays in domain module! Priceless Domain Logic Domain Objects What's specific to your app
  • 19. 19 VictorRentea.ro a training by External Service domain DTO call Domain Service
  • 20. 20 VictorRentea.ro a training by External Service DTO Adapter Domain Service Domain Service <dependency> domain infrastructure Goal: Keep Your Precious Domain isolated from external influences may slip in DTO
  • 21. VictorRentea.ro 21 External Service DTO IAdapter Adapter implements class UserApiClient implements IUserAdapter { public User getById(id){ <external call> } } interface IUserAdapter { User getById(id); } class OrderService { @Autowired IUserAdapter adapter; ... adapter.getById(id); } express your need in a domain interface… and implement it in a lower-level module… When you need to call outside… so nothing foreign enters your domain. Domain Service Domain Service <dependency> domain infrastructure DTO
  • 22. 22 VictorRentea.ro a training by calls Dependency Inversion Principle <dependency> higher-level module lower-level module "Best of OOP" - Uncle Bob Abstractions should not depend on details Low level classes are not visible (SOLID Principles) Dependency Inversion
  • 23. 23 VictorRentea.ro a training by calls <dependency> higher-level module lower-level module RMI, HTTP GRPC.. FTP Queue DB DTO Dependency Inversion
  • 24. 24 VictorRentea.ro a training by Stop Code Dependencies Dependency Inversion Package Dependency Checks - by static code analysis - by compiler @Test public void dependencyInversionTest() { ArchRuleDefinition .noClasses().that().resideInAPackage("..domain") .should().dependOnClassesThat().resideInAPackage("..infra") .check(new ClassFileImporter().importPackages("my.corp.app")); } testImplementation com.tngtech.archunit:archunit-junit4:0.15.0 or NDepend (C#) https://nx.dev/latest/angular/structure/monorepo-tags https://github.com/MaibornWolff/ts-arch
  • 25. 25 VictorRentea.ro a training by An Agnostic Domain lets you focus on YOUR logic Agnostic Domain
  • 26. 27 VictorRentea.ro a training by infrastructure EXTERNAL API Value Object Entity id Domain Service IAdapter Onion Architecture Behold, the famous Database domain Repo Dep Inv Dep Inv DTO Agnostic Domain application DTO Your Client Validation Separate Persistence Model if DB == enemy Façade Mapper Controller Adapter Spring Data IRepo
  • 27. 28 VictorRentea.ro a training by 28 DTO Value Object Entity id Domain Service application Database domain DTO Onion Architecture Pragmatic Agnostic Domain EXTERNAL API Your Client Façade Mapper Controller Adapter IAdapter IRepo Dep Inv
  • 28. 29 VictorRentea.ro a training by Independent of Intrusive Frameworks Testable Standalone without a DB, UI, Web Server, etc... https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html Independent of UI mobile, web, or desktop Independent of DB avoid PL/SQL, no vendor lock-in Independent of External APIs = external Bounded Contexts Is an ORM intrusive? Keep core logic ... Agnostic Domain aka Hexagonal aka Ports-and-Adapters aka Clean Architecture Onion Architecture
  • 29. 31 VictorRentea.ro a training by Keep Domain Object design independent of persistence Decompose large flat Entities with @Embeddable Avoid useless IDs with @ElementCollection Constructor constraints are possible, hiding default one Question entity links. Aren't IDs enough? Designing Expressive and Performant Persistence Models https://www.youtube.com/watch?v=iw0tOx7Zbjc Legacy DB Schema ➔ Separate Models Mappers ➔ Pain Avoid bi-directional links
  • 30. 32 VictorRentea.ro a training by Axiom 1: Logic is simpler if implemented using data structures we control Smaller: only the 5 required fields, not all 20 OOP: with helper methods inside Safer: null-safe, guarding invariants, immutable? Extract Value Objects Split Large Entities vs BC Keep DTOs out
  • 31. 33 VictorRentea.ro a training by Extract Value Objects from Entities Chapter 2
  • 32. 34 VictorRentea.ro a training by How many fields it has? Can you make it immutable? Tell me about that big entity ... How do you feel about moving logic inside?
  • 33. 35 VictorRentea.ro a training by How many fields it has? Can you make it immutable? How do you feel about moving logic inside? Yes! (use @Embeddable for JPA) But, How to identify Value Objects? Extract Value Objects from Entities:
  • 34. 36 VictorRentea.ro a training by Conceptual Whole Money {amount, currency} Changes Together LastModifiedBy/Time How to identify Value Objects? Screens InvoicingDetails Moves Together PriceComputationInput
  • 35. 37 VictorRentea.ro a training by Chapter 3 The Confused Entity
  • 36. 38 VictorRentea.ro a training by What's bad with Legacy Code? Old-style, -frameworks Massive Unknown Code Excessive Coupling
  • 38. 40 VictorRentea.ro a training by Order Product «entity» Product 40 fields «entity» Product 15 fields «entity» Product 30 fields
  • 39. 41 VictorRentea.ro a training by Order Product «entity» Product 15 fields «entity» Product 30 fields
  • 40. 42 VictorRentea.ro a training by Axiom 1: Logic is simpler if implemented using data structures we control Smaller: only the 5 required fields, not all 20 OOP: with helper methods inside Safer: null-safe, guarding invariants, immutable? Extract Value Objects Split Large Entities vs BC Keep DTOs out
  • 41. Axiom 1: Logic is simpler if implemented using data structures we control Clean Architecture Thank you! victorrentea@gmail.com VictorRentea.ro @victorrentea