SlideShare a Scribd company logo
Clean architecture - Protecting the Domain
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
Clean architecture - Protecting the Domain
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

PDF
Clean pragmatic architecture @ devflix
PPTX
Clean Pragmatic Architecture - Avoiding a Monolith
PDF
Introducing Clean Architecture
PDF
Real Life Clean Architecture
PPTX
The tests are trying to tell you something@VoxxedBucharest.pptx
PDF
Clean Architecture
PPTX
Clean architecture
PDF
Clean Architecture
Clean pragmatic architecture @ devflix
Clean Pragmatic Architecture - Avoiding a Monolith
Introducing Clean Architecture
Real Life Clean Architecture
The tests are trying to tell you something@VoxxedBucharest.pptx
Clean Architecture
Clean architecture
Clean Architecture

What's hot (20)

PDF
Clean architecture
PDF
Integration testing with spring @snow one
PPTX
Vertical Slicing Architectures
PPTX
The Clean Architecture
PPTX
Functional Patterns with Java8 @Bucharest Java User Group
PDF
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
PPT
Domain Driven Design (DDD)
PDF
Don't Be Mocked by your Mocks - Best Practices using Mocks
PPTX
OutSystems Tricks & Tips for Complex UI Integrations
PDF
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
PDF
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
PDF
Clean Lambdas & Streams in Java8
PPTX
Clean architecture
PDF
Clean code
PPTX
Clean Architecture
PPTX
Domain Driven Design 101
PPTX
Clean Code I - Best Practices
PDF
Networking in Java with NIO and Netty
PDF
Domain Driven Design
PPTX
Domain driven design
Clean architecture
Integration testing with spring @snow one
Vertical Slicing Architectures
The Clean Architecture
Functional Patterns with Java8 @Bucharest Java User Group
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Domain Driven Design (DDD)
Don't Be Mocked by your Mocks - Best Practices using Mocks
OutSystems Tricks & Tips for Complex UI Integrations
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Clean Lambdas & Streams in Java8
Clean architecture
Clean code
Clean Architecture
Domain Driven Design 101
Clean Code I - Best Practices
Networking in Java with NIO and Netty
Domain Driven Design
Domain driven design
Ad

Similar to Clean architecture - Protecting the Domain (20)

PPTX
Test-Driven Design Insights@DevoxxBE 2023.pptx
PDF
Java Programming
PDF
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
PPTX
Game Studio
PPTX
Framework Design Guidelines For Brussels Users Group
PDF
Eugene Burmako
PPTX
Effective Java
PPTX
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
DOCX
Patterns (contd)Software Development ProcessDesign patte.docx
PDF
Mihai Tataran - Building Windows 8 Applications with HTML5 and JS
PPTX
Using Boundary-Driven Development to beat code complexity
PDF
Top 50 .NET Interview Questions and Answers 2019 | Edureka
PPT
Encapsulation
PDF
Elements of DDD with ASP.NET MVC & Entity Framework Code First
PPTX
Mocking vtcc3 - en
PDF
Modern JavaScript Applications: Design Patterns
PDF
Mini-Training: Javascript Patterns
PPTX
.NET Attributes and Reflection - What a Developer Needs to Know...
PPTX
Developing Actors in Azure with .net
PPT
SDWest2005Goetsch
Test-Driven Design Insights@DevoxxBE 2023.pptx
Java Programming
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
Game Studio
Framework Design Guidelines For Brussels Users Group
Eugene Burmako
Effective Java
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Patterns (contd)Software Development ProcessDesign patte.docx
Mihai Tataran - Building Windows 8 Applications with HTML5 and JS
Using Boundary-Driven Development to beat code complexity
Top 50 .NET Interview Questions and Answers 2019 | Edureka
Encapsulation
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Mocking vtcc3 - en
Modern JavaScript Applications: Design Patterns
Mini-Training: Javascript Patterns
.NET Attributes and Reflection - What a Developer Needs to Know...
Developing Actors in Azure with .net
SDWest2005Goetsch
Ad

More from Victor Rentea (20)

PDF
Top REST API Desgin Pitfalls @ Devoxx 2024
PDF
The Joy of Testing - Deep Dive @ Devoxx Belgium 2024
PDF
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
PDF
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
PDF
Microservice Resilience Patterns @VoxxedCern'24
PDF
Distributed Consistency.pdf
PDF
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
PDF
Testing Microservices @DevoxxBE 23.pdf
PPTX
From Web to Flux @DevoxxBE 2023.pptx
PDF
Profiling your Java Application
PPTX
OAuth in the Wild
PDF
Software Craftsmanship @Code Camp Festival 2022.pdf
PDF
Unit testing - 9 design hints
PPTX
Extreme Professionalism - Software Craftsmanship
PDF
Refactoring blockers and code smells @jNation 2021
PDF
Hibernate and Spring - Unleash the Magic
PDF
Integration testing with spring @JAX Mainz
PDF
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
PDF
Pure functions and immutable objects @dev nexus 2021
PDF
TDD Mantra
Top REST API Desgin Pitfalls @ Devoxx 2024
The Joy of Testing - Deep Dive @ Devoxx Belgium 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Microservice Resilience Patterns @VoxxedCern'24
Distributed Consistency.pdf
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Testing Microservices @DevoxxBE 23.pdf
From Web to Flux @DevoxxBE 2023.pptx
Profiling your Java Application
OAuth in the Wild
Software Craftsmanship @Code Camp Festival 2022.pdf
Unit testing - 9 design hints
Extreme Professionalism - Software Craftsmanship
Refactoring blockers and code smells @jNation 2021
Hibernate and Spring - Unleash the Magic
Integration testing with spring @JAX Mainz
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
Pure functions and immutable objects @dev nexus 2021
TDD Mantra

Recently uploaded (20)

PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Nekopoi APK 2025 free lastest update
PDF
AI in Product Development-omnex systems
PPTX
Introduction to Artificial Intelligence
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Essential Infomation Tech presentation.pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
How Creative Agencies Leverage Project Management Software.pdf
Nekopoi APK 2025 free lastest update
AI in Product Development-omnex systems
Introduction to Artificial Intelligence
VVF-Customer-Presentation2025-Ver1.9.pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Which alternative to Crystal Reports is best for small or large businesses.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
How to Choose the Right IT Partner for Your Business in Malaysia
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Essential Infomation Tech presentation.pptx
Transform Your Business with a Software ERP System
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
wealthsignaloriginal-com-DS-text-... (1).pdf
ai tools demonstartion for schools and inter college
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41

Clean architecture - Protecting the Domain

  • 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
  • 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