SlideShare a Scribd company logo
Pursuing Domain-Driven Design practices in PHP
Who am I Giorgio Sironi Bachelor in Computer Engineering Advisor @ Allbus Zone Leader @ DZone
The long title Pursuing Domain-Driven Design practices in PHP
The DDD box of goods Knowledge crunching Ubiquitous Language Domain Model Refactoring towards deeper insight... Collaboration patterns (Anti-corruption layer, Separate ways, ...)
Why? (the most important slide) Close to business, to follow its changes aids iterative development The code is the design supported by blackboards and UML Test and develop with in-memory objects no instantiation of Oracle connections It's also fun! exercise creativity and learning skills
Domain Model Reflects knowledge of the domain  more  than technology While there is value in the item on the right, we value the item on the left more Persistence-agnostic (UnitOfWork) In general, no outward dependencies
Step 1: from relational... user id username password active user_group id_user id_group group id name logo
Step 1: ...to object-oriented class User { } class Group { }
Step 2: from Active Record... class Group extends Doctrine_Record { } Hard dependency towards ORM Inherits pollution from Doctrine_Record
Step 2: … to Data Mapper /** * @Entity */ class User  { }
Building blocks Entity Value Object Aggregate Repository Factory Service Other transient objects (Specification, ...)
Entity More than a row Equality is based on identity e.g. Post #42, user 'giorgiosironi', … The bread and butter of your Domain Model
Value Object Previously known in the world as  value e.g. the number 42, Zip code 22031, #FF0000 Equality based on values Immutable in certain implementations
Aggregate Subgraph of Entities and Value Objects with a single entry: the root possible multiple exits, mostly to follow during reading Unit of consistency: loose correspondency to database transactions
Checkpoint:  data modeling
Repository The gate to the database One aggregate at the time The illusion of an in-memory collection of Entities (Fowler's definition)
Factory Encapsulate creation of complex Aggregates a new() is often all you need
Service At the  domain  level Introduced to avoid mutual dependencies, or field references to strange things, in Entities&Value Objects Optimal for isolation from libraries
Checkpoint:  lifecycle classes
Meanwhile, in PHP...
Active Record vs. Data Mapper Doctrine 2 for persistence (see tutorial by @juokaz) By default for Doctrine 2 object === row All the tricks are at http://github.com/giorgiosironi/ddd-talk
Entity @Entity annotation no  extends @Column for fields private fields types are PHP types:  string , not  varchar
Value Objects Do you want an (id, date) table? Serialization of the whole object Conversion into a custom string/numerical format via a custom DBAL data type Deconstruction/reconstruction with lifecycle hooks Combined approaches: serialization and mirror fields
Aggregate Relationships:  @OneToMany, @ManyToMany, @OneToOne, … @OneToMany(..., cascade={“persist”, “remove”}) @OneToMany(..., orphanRemoval=true) @ManyToMany(targetEntity="Phonenumber") @JoinTable(..., inverseJoinColumns={name=”phonenumber_id", referencedColumnName="id", unique=true)
Repository Plain Old PHP Object Composing EntityManager It's possible to define EntityManager custom repositories: quick and dirty Encapsulates queries Typical methods: add($root), remove($root), find($id), findByStrangeCriteria() It's a collection!
Factory, Service POPO Sometimes composing services or infrastructure objects (e.g. generating new progressive number for invoices, calculate current taxes, sending mails...) Often decoupled with an interface
References The code shown in this talk http://github.com/giorgiosironi/ddd-talk Four books http://domaindrivendesign.org/books Domain-Driven Design mailing list Google that :)
Q/A
Thanks for your attention

More Related Content

ODP
Testing in isolation
PDF
Pursuing practices of Domain-Driven Design in PHP
PDF
C# Summer course - Lecture 1
PPTX
Object Oriented Concept
PPTX
Std 12 computer chapter 6 object oriented concepts (part 1)
PDF
Session 1.2 high-precision, context-free entity linking exploiting unambigu...
PPTX
Lecture01 object oriented-programming
PPT
Object Oriented Programming In .Net
Testing in isolation
Pursuing practices of Domain-Driven Design in PHP
C# Summer course - Lecture 1
Object Oriented Concept
Std 12 computer chapter 6 object oriented concepts (part 1)
Session 1.2 high-precision, context-free entity linking exploiting unambigu...
Lecture01 object oriented-programming
Object Oriented Programming In .Net

What's hot (20)

PDF
Oop concepts classes_objects
PPTX
Brownfield Domain Driven Design
PPTX
Advance oops concepts
PPT
Oops ppt
PPTX
Object oriented programming concepts
PPTX
OOPS with C++ | Concepts of OOPS | Introduction
PPTX
Vb ch 3-object-oriented_fundamentals_in_vb.net
PPT
Chapter1 - Introduction to Object-Oriented Programming and Software Development
PPT
Oops Concepts
PPTX
Unit 1 OOSE
PDF
Object-oriented programming (OOP) with Complete understanding modules
PDF
Java day2016 "Reinventing design patterns with java 8"
PDF
Qb it1301
PPT
Basic concepts of object oriented programming
PDF
Object Oriented Concepts in Real Projects
PPTX
concept of oops
PPT
Object oriented programming using c++
Oop concepts classes_objects
Brownfield Domain Driven Design
Advance oops concepts
Oops ppt
Object oriented programming concepts
OOPS with C++ | Concepts of OOPS | Introduction
Vb ch 3-object-oriented_fundamentals_in_vb.net
Chapter1 - Introduction to Object-Oriented Programming and Software Development
Oops Concepts
Unit 1 OOSE
Object-oriented programming (OOP) with Complete understanding modules
Java day2016 "Reinventing design patterns with java 8"
Qb it1301
Basic concepts of object oriented programming
Object Oriented Concepts in Real Projects
concept of oops
Object oriented programming using c++
Ad

Viewers also liked (6)

ODP
An year of Pomodoros
ODP
#pugMi - DDD - Value objects
PPTX
PHP framework Phalcon
PPTX
Domain Driven Design using Laravel
PDF
The Perils of Perception in 2016: Ipsos MORI
PDF
Software Design Patterns in Laravel by Phill Sparks
An year of Pomodoros
#pugMi - DDD - Value objects
PHP framework Phalcon
Domain Driven Design using Laravel
The Perils of Perception in 2016: Ipsos MORI
Software Design Patterns in Laravel by Phill Sparks
Ad

Similar to Pursuing Domain-Driven Design practices in PHP (20)

PDF
What is DDD and how could it help you
PPTX
Domain Driven Design
PPTX
Implementing DDD Concepts in PHP
PPTX
Introduction to DDD
PDF
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
PPTX
.NET Fest 2019. Halil Ibrahim Kalkan. Implementing Domain Driven Design
KEY
Object Relational Mapping in PHP
PPTX
Practical domain driven design
PDF
IPC07 Talk - Beautiful Code with AOP and DI
PPTX
Zend Framework And Doctrine
PDF
Domain driven design: a gentle introduction
ODP
Introduction to Domain-Driven Design
PDF
From ddd to DDD : My journey from data-driven development to Domain-Driven De...
PDF
DDD on example of Symfony (SfCampUA14)
PPTX
An Introduction to Domain Driven Design in PHP
PDF
Enterprise PHP Architecture through Design Patterns and Modularization (Midwe...
PPT
Domain Driven Design (DDD)
PDF
Beyond MVC: from Model to Domain
PDF
Doctrine Php Object Relational Mapper
PPTX
PHP Starter Application
What is DDD and how could it help you
Domain Driven Design
Implementing DDD Concepts in PHP
Introduction to DDD
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
.NET Fest 2019. Halil Ibrahim Kalkan. Implementing Domain Driven Design
Object Relational Mapping in PHP
Practical domain driven design
IPC07 Talk - Beautiful Code with AOP and DI
Zend Framework And Doctrine
Domain driven design: a gentle introduction
Introduction to Domain-Driven Design
From ddd to DDD : My journey from data-driven development to Domain-Driven De...
DDD on example of Symfony (SfCampUA14)
An Introduction to Domain Driven Design in PHP
Enterprise PHP Architecture through Design Patterns and Modularization (Midwe...
Domain Driven Design (DDD)
Beyond MVC: from Model to Domain
Doctrine Php Object Relational Mapper
PHP Starter Application

More from Giorgio Sironi (19)

ODP
Case study: Khan Academy
ODP
Case study: iTunes for K-12
ODP
Case study: Insegnalo
ODP
Case study: Innovascuola
ODP
Case study: e-Learning for Kids
ODP
Case study: Chocolat 3B
PDF
Khan Academy
PDF
Itunes K-12
PDF
Insegnalo
PDF
Innovascuola
PDF
e-Learning for kids
PDF
Chocolat 3B
ODP
Blind detection of image manipulation @ PoliMi
ODP
CouchDB @ PoliMi
PDF
Cohesion and coupling metrics for workflow process design
ODP
PHP Barcelona 2010 - Architecture and testability
ODP
Chansonnier: web application for multimedia search on song videos
ODP
Chansonnier: web application for multimedia search on song videos
ODP
Php day2010
Case study: Khan Academy
Case study: iTunes for K-12
Case study: Insegnalo
Case study: Innovascuola
Case study: e-Learning for Kids
Case study: Chocolat 3B
Khan Academy
Itunes K-12
Insegnalo
Innovascuola
e-Learning for kids
Chocolat 3B
Blind detection of image manipulation @ PoliMi
CouchDB @ PoliMi
Cohesion and coupling metrics for workflow process design
PHP Barcelona 2010 - Architecture and testability
Chansonnier: web application for multimedia search on song videos
Chansonnier: web application for multimedia search on song videos
Php day2010

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
Teaching material agriculture food technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Review of recent advances in non-invasive hemoglobin estimation
Spectral efficient network and resource selection model in 5G networks
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
“AI and Expert System Decision Support & Business Intelligence Systems”
Agricultural_Statistics_at_a_Glance_2022_0.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Chapter 3 Spatial Domain Image Processing.pdf
Teaching material agriculture food technology
Encapsulation_ Review paper, used for researhc scholars
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding

Pursuing Domain-Driven Design practices in PHP

  • 1. Pursuing Domain-Driven Design practices in PHP
  • 2. Who am I Giorgio Sironi Bachelor in Computer Engineering Advisor @ Allbus Zone Leader @ DZone
  • 3. The long title Pursuing Domain-Driven Design practices in PHP
  • 4. The DDD box of goods Knowledge crunching Ubiquitous Language Domain Model Refactoring towards deeper insight... Collaboration patterns (Anti-corruption layer, Separate ways, ...)
  • 5. Why? (the most important slide) Close to business, to follow its changes aids iterative development The code is the design supported by blackboards and UML Test and develop with in-memory objects no instantiation of Oracle connections It's also fun! exercise creativity and learning skills
  • 6. Domain Model Reflects knowledge of the domain more than technology While there is value in the item on the right, we value the item on the left more Persistence-agnostic (UnitOfWork) In general, no outward dependencies
  • 7. Step 1: from relational... user id username password active user_group id_user id_group group id name logo
  • 8. Step 1: ...to object-oriented class User { } class Group { }
  • 9. Step 2: from Active Record... class Group extends Doctrine_Record { } Hard dependency towards ORM Inherits pollution from Doctrine_Record
  • 10. Step 2: … to Data Mapper /** * @Entity */ class User { }
  • 11. Building blocks Entity Value Object Aggregate Repository Factory Service Other transient objects (Specification, ...)
  • 12. Entity More than a row Equality is based on identity e.g. Post #42, user 'giorgiosironi', … The bread and butter of your Domain Model
  • 13. Value Object Previously known in the world as value e.g. the number 42, Zip code 22031, #FF0000 Equality based on values Immutable in certain implementations
  • 14. Aggregate Subgraph of Entities and Value Objects with a single entry: the root possible multiple exits, mostly to follow during reading Unit of consistency: loose correspondency to database transactions
  • 15. Checkpoint: data modeling
  • 16. Repository The gate to the database One aggregate at the time The illusion of an in-memory collection of Entities (Fowler's definition)
  • 17. Factory Encapsulate creation of complex Aggregates a new() is often all you need
  • 18. Service At the domain level Introduced to avoid mutual dependencies, or field references to strange things, in Entities&Value Objects Optimal for isolation from libraries
  • 21. Active Record vs. Data Mapper Doctrine 2 for persistence (see tutorial by @juokaz) By default for Doctrine 2 object === row All the tricks are at http://github.com/giorgiosironi/ddd-talk
  • 22. Entity @Entity annotation no extends @Column for fields private fields types are PHP types: string , not varchar
  • 23. Value Objects Do you want an (id, date) table? Serialization of the whole object Conversion into a custom string/numerical format via a custom DBAL data type Deconstruction/reconstruction with lifecycle hooks Combined approaches: serialization and mirror fields
  • 24. Aggregate Relationships: @OneToMany, @ManyToMany, @OneToOne, … @OneToMany(..., cascade={“persist”, “remove”}) @OneToMany(..., orphanRemoval=true) @ManyToMany(targetEntity="Phonenumber") @JoinTable(..., inverseJoinColumns={name=”phonenumber_id", referencedColumnName="id", unique=true)
  • 25. Repository Plain Old PHP Object Composing EntityManager It's possible to define EntityManager custom repositories: quick and dirty Encapsulates queries Typical methods: add($root), remove($root), find($id), findByStrangeCriteria() It's a collection!
  • 26. Factory, Service POPO Sometimes composing services or infrastructure objects (e.g. generating new progressive number for invoices, calculate current taxes, sending mails...) Often decoupled with an interface
  • 27. References The code shown in this talk http://github.com/giorgiosironi/ddd-talk Four books http://domaindrivendesign.org/books Domain-Driven Design mailing list Google that :)
  • 28. Q/A
  • 29. Thanks for your attention