SlideShare a Scribd company logo
1 of 26
Practical DDD
@Bauno
Disclaimer
...and so it begins...
- Libro di Evans del 2004
- Descrive (prescrive?) un insieme
di patterns e metodologie di
analisi e implementazione
“Talk is cheap, show me the code”
“DDD...show me the code”
@emadb, 2011
DDD Purpose
● To build a domain (business) model, NOT a data model (anaemic domain)
● To express domain concepts in the code
● To make the implicit explicit (including, but not limited to, errors)
Strategic tools
● Ubiquitous language (Domain experts)
● Bounded context
● Core domain (distillation)
Bounded context
● It’s impossible to build and
maintain a model for a large,
complex organization: divide et
impera
● The preferred way of
communication between
bounded contexts is using Domain
Events via pub/sub
Ubiquitous language
● Rigourous language, no ambiguity
● It’s the language we use in the code, to name our domain concepts
● Usually valid only inside a bounded context
Core domain distillation
● DDD is expensive both in analysis and implementation, so it’s important
to know where to use it
● Every large domain has various supporting subdomains for every core
domain
● Usually found following the money :-)
Tactical tools
● Entities
● Aggregates
● Value Objects
● Domain services
● Domain events
● Repositories
● Factories (anti corruption layer)
Entities and Aggregates
● An entity is just a PO(C|J)O object that
expresses a domain concept and
enforces the domain invariant(s)
● Persistence ignorance
● Holds the business logic of the domain
and its state
● Has an identity throughout the
bounded context (Identity equality)
● An aggregate is a transaction
boundary consisting in several entities
held together by an aggregate root
Value Objects
● Plain simple records
● Immutable
● Structural equality (no identity)
Entities vs Value Objects
● Should this be and Entity or a Value Object? The answer can be subtle or
obvious, and depends mostly on the context
● Usually in a 70/30 ratio
Domain Services
● “The operation relates to a domain concept that is not a natural part of an
Entity or Value Object”
● First class citizens of the domain
● Stateless
Domain Events
● “Nel dominio è successo qualcosa di interessante per un domain expert”
● Can (asynchronously) cross the boundaries of an aggregate
● Compensating events
Repositories
● A repository is a class whose sole purpose is to collaborate with an entity for
data persistence
● SRP is enforced
● Emphasys on the data access pattern, which is made explicit
Factories/Validators
● Responsibles for creating the entities
● Anti corruption layer
● The domain has to be always valid, creating entities in invalid state must
be impossible
● Usually there is a strong coupling between factories and the entities they
create, but that’s ok.
Resulting
architecture
Warning: wrong place for domain
services
Testing
● The core domain has to be
unit tested, ideally with a
100% coverage
● I usually test factories and
repositories in integration
CQS (Command-Query Separation)
CQRS (Command Query Responsibility Separation)
DDD + CQ(R)S
● Only way I’ve found to write a reliable, rock solid DOMAIN model
● Domain Entities
○ Enforces invariants
○ Express business model, relationships
○ Have only public methods
○ They’re the write part of the model
● Views
○ Used for queries:
○ Very dumb, no business logic (only a little, if any, of presentation logic)
○ They’re read-only for the domain (i.e.: they come out, never go in)
○ Tailored to the specific user view (there are A LOT of views, but that’s ok)
How I do it (with a single RDBMS)
public interface IDbDto<DTO> {
TDto ToDto();
void Load(TDto dto);
}
- Dtos are the ONLY data saved to and loaded from the database
- The interface is hidden until we do a cast (which can only be done in the repository)
- The Dtos are used to hydrate (fill the data in) the views and the entities alike
Every entity explicitly implements the interface IDbDto
● Very dumb class
● No constructor
● Everything is public
● Usually denormalized
● Read-only for the domain
● Constructor sets the identity
● Class enforces domain invariants
● No public properties (even read-only)
● Public methods only
● State is completely private
public class Cart : IDbDto<CartDto>
{
public Guid Id {get; }
public Cart (Customer
customer);
public Unit AddItem(Item item);
public Unit CheckOut();
}
public class CartView
{
public ItemView[] Items {get; set}
public string CustomerName {get;
set;}
public string CustomerAddress {get;
set;}
public double Amount {get; set;}
}
public class CartDto
{
public Guid Id {get; set}
public Guid CustomerId {get;
set}
public ItemDto[] Items;
}
● Another dumb class
● Usually Normalized
● No constructor, public
● This is where an ORM
may be handy
Functional DDD
● Really? It’s intrinsically anaemic (Record + Services)
● CQRS (State as application of a series of events) fits better
Questions?
?

More Related Content

Similar to Practical domain driven design

Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)Tom Kocjan
 
Brownfield Domain Driven Design
Brownfield Domain Driven DesignBrownfield Domain Driven Design
Brownfield Domain Driven DesignNicolò Pignatelli
 
Baby steps to Domain-Driven Design
Baby steps to Domain-Driven DesignBaby steps to Domain-Driven Design
Baby steps to Domain-Driven DesignŽilvinas Kuusas
 
The working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор ТурскийThe working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор ТурскийSigma Software
 
The working architecture of node js applications open tech week javascript ...
The working architecture of node js applications   open tech week javascript ...The working architecture of node js applications   open tech week javascript ...
The working architecture of node js applications open tech week javascript ...Viktor Turskyi
 
Idiomatic Domain Driven Design: implementing CQRS
Idiomatic Domain Driven Design: implementing CQRSIdiomatic Domain Driven Design: implementing CQRS
Idiomatic Domain Driven Design: implementing CQRSAndrea Saltarello
 
Domain driven design: a gentle introduction
Domain driven design:  a gentle introductionDomain driven design:  a gentle introduction
Domain driven design: a gentle introductionAsher Sterkin
 
Structuring the code
Structuring the codeStructuring the code
Structuring the codeIman Tunggono
 
2011-05-22 Domain Driven Design
2011-05-22 Domain Driven Design2011-05-22 Domain Driven Design
2011-05-22 Domain Driven DesignIsmael Santos
 
From class to architecture
From class to architectureFrom class to architecture
From class to architectureMarcin Hawraniak
 
Importance Of Being Driven
Importance Of Being DrivenImportance Of Being Driven
Importance Of Being DrivenAntonio Terreno
 
Adopting Domain-Driven Design in your organization
Adopting Domain-Driven Design in your organizationAdopting Domain-Driven Design in your organization
Adopting Domain-Driven Design in your organizationAleix Morgadas
 
Umbraco development across large and distributed teams
Umbraco development across large and distributed teamsUmbraco development across large and distributed teams
Umbraco development across large and distributed teamsJanusz Stabik
 
Oracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleOracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleEDB
 
Fighting legacy with hexagonal architecture and frameworkless php
Fighting legacy with hexagonal architecture and frameworkless phpFighting legacy with hexagonal architecture and frameworkless php
Fighting legacy with hexagonal architecture and frameworkless phpFabio Pellegrini
 
Epic.NET: Processes, patterns and architectures
Epic.NET: Processes, patterns and architecturesEpic.NET: Processes, patterns and architectures
Epic.NET: Processes, patterns and architecturesGiacomo Tesio
 
Feedback on DDD Europe - short -event storming.pptx
Feedback on DDD Europe - short -event storming.pptxFeedback on DDD Europe - short -event storming.pptx
Feedback on DDD Europe - short -event storming.pptxGuillaume Saint Etienne
 

Similar to Practical domain driven design (20)

Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
 
Brownfield Domain Driven Design
Brownfield Domain Driven DesignBrownfield Domain Driven Design
Brownfield Domain Driven Design
 
Baby steps to Domain-Driven Design
Baby steps to Domain-Driven DesignBaby steps to Domain-Driven Design
Baby steps to Domain-Driven Design
 
The working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор ТурскийThe working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор Турский
 
The working architecture of node js applications open tech week javascript ...
The working architecture of node js applications   open tech week javascript ...The working architecture of node js applications   open tech week javascript ...
The working architecture of node js applications open tech week javascript ...
 
API Design
API DesignAPI Design
API Design
 
Idiomatic Domain Driven Design: implementing CQRS
Idiomatic Domain Driven Design: implementing CQRSIdiomatic Domain Driven Design: implementing CQRS
Idiomatic Domain Driven Design: implementing CQRS
 
Introdução à Elixir
Introdução à ElixirIntrodução à Elixir
Introdução à Elixir
 
Domain driven design: a gentle introduction
Domain driven design:  a gentle introductionDomain driven design:  a gentle introduction
Domain driven design: a gentle introduction
 
Structuring the code
Structuring the codeStructuring the code
Structuring the code
 
2011-05-22 Domain Driven Design
2011-05-22 Domain Driven Design2011-05-22 Domain Driven Design
2011-05-22 Domain Driven Design
 
2011-05-22 Domain Driven Design
2011-05-22 Domain Driven Design2011-05-22 Domain Driven Design
2011-05-22 Domain Driven Design
 
From class to architecture
From class to architectureFrom class to architecture
From class to architecture
 
Importance Of Being Driven
Importance Of Being DrivenImportance Of Being Driven
Importance Of Being Driven
 
Adopting Domain-Driven Design in your organization
Adopting Domain-Driven Design in your organizationAdopting Domain-Driven Design in your organization
Adopting Domain-Driven Design in your organization
 
Umbraco development across large and distributed teams
Umbraco development across large and distributed teamsUmbraco development across large and distributed teams
Umbraco development across large and distributed teams
 
Oracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleOracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration Hustle
 
Fighting legacy with hexagonal architecture and frameworkless php
Fighting legacy with hexagonal architecture and frameworkless phpFighting legacy with hexagonal architecture and frameworkless php
Fighting legacy with hexagonal architecture and frameworkless php
 
Epic.NET: Processes, patterns and architectures
Epic.NET: Processes, patterns and architecturesEpic.NET: Processes, patterns and architectures
Epic.NET: Processes, patterns and architectures
 
Feedback on DDD Europe - short -event storming.pptx
Feedback on DDD Europe - short -event storming.pptxFeedback on DDD Europe - short -event storming.pptx
Feedback on DDD Europe - short -event storming.pptx
 

Recently uploaded

Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 

Recently uploaded (20)

Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 

Practical domain driven design

  • 3. ...and so it begins... - Libro di Evans del 2004 - Descrive (prescrive?) un insieme di patterns e metodologie di analisi e implementazione
  • 4. “Talk is cheap, show me the code” “DDD...show me the code” @emadb, 2011
  • 5. DDD Purpose ● To build a domain (business) model, NOT a data model (anaemic domain) ● To express domain concepts in the code ● To make the implicit explicit (including, but not limited to, errors)
  • 6. Strategic tools ● Ubiquitous language (Domain experts) ● Bounded context ● Core domain (distillation)
  • 7. Bounded context ● It’s impossible to build and maintain a model for a large, complex organization: divide et impera ● The preferred way of communication between bounded contexts is using Domain Events via pub/sub
  • 8. Ubiquitous language ● Rigourous language, no ambiguity ● It’s the language we use in the code, to name our domain concepts ● Usually valid only inside a bounded context
  • 9. Core domain distillation ● DDD is expensive both in analysis and implementation, so it’s important to know where to use it ● Every large domain has various supporting subdomains for every core domain ● Usually found following the money :-)
  • 10. Tactical tools ● Entities ● Aggregates ● Value Objects ● Domain services ● Domain events ● Repositories ● Factories (anti corruption layer)
  • 11. Entities and Aggregates ● An entity is just a PO(C|J)O object that expresses a domain concept and enforces the domain invariant(s) ● Persistence ignorance ● Holds the business logic of the domain and its state ● Has an identity throughout the bounded context (Identity equality) ● An aggregate is a transaction boundary consisting in several entities held together by an aggregate root
  • 12. Value Objects ● Plain simple records ● Immutable ● Structural equality (no identity)
  • 13. Entities vs Value Objects ● Should this be and Entity or a Value Object? The answer can be subtle or obvious, and depends mostly on the context ● Usually in a 70/30 ratio
  • 14. Domain Services ● “The operation relates to a domain concept that is not a natural part of an Entity or Value Object” ● First class citizens of the domain ● Stateless
  • 15. Domain Events ● “Nel dominio è successo qualcosa di interessante per un domain expert” ● Can (asynchronously) cross the boundaries of an aggregate ● Compensating events
  • 16. Repositories ● A repository is a class whose sole purpose is to collaborate with an entity for data persistence ● SRP is enforced ● Emphasys on the data access pattern, which is made explicit
  • 17. Factories/Validators ● Responsibles for creating the entities ● Anti corruption layer ● The domain has to be always valid, creating entities in invalid state must be impossible ● Usually there is a strong coupling between factories and the entities they create, but that’s ok.
  • 19. Testing ● The core domain has to be unit tested, ideally with a 100% coverage ● I usually test factories and repositories in integration
  • 21. CQRS (Command Query Responsibility Separation)
  • 22. DDD + CQ(R)S ● Only way I’ve found to write a reliable, rock solid DOMAIN model ● Domain Entities ○ Enforces invariants ○ Express business model, relationships ○ Have only public methods ○ They’re the write part of the model ● Views ○ Used for queries: ○ Very dumb, no business logic (only a little, if any, of presentation logic) ○ They’re read-only for the domain (i.e.: they come out, never go in) ○ Tailored to the specific user view (there are A LOT of views, but that’s ok)
  • 23. How I do it (with a single RDBMS) public interface IDbDto<DTO> { TDto ToDto(); void Load(TDto dto); } - Dtos are the ONLY data saved to and loaded from the database - The interface is hidden until we do a cast (which can only be done in the repository) - The Dtos are used to hydrate (fill the data in) the views and the entities alike Every entity explicitly implements the interface IDbDto
  • 24. ● Very dumb class ● No constructor ● Everything is public ● Usually denormalized ● Read-only for the domain ● Constructor sets the identity ● Class enforces domain invariants ● No public properties (even read-only) ● Public methods only ● State is completely private public class Cart : IDbDto<CartDto> { public Guid Id {get; } public Cart (Customer customer); public Unit AddItem(Item item); public Unit CheckOut(); } public class CartView { public ItemView[] Items {get; set} public string CustomerName {get; set;} public string CustomerAddress {get; set;} public double Amount {get; set;} } public class CartDto { public Guid Id {get; set} public Guid CustomerId {get; set} public ItemDto[] Items; } ● Another dumb class ● Usually Normalized ● No constructor, public ● This is where an ORM may be handy
  • 25. Functional DDD ● Really? It’s intrinsically anaemic (Record + Services) ● CQRS (State as application of a series of events) fits better