DDD in PHP

Domain-Driven Design transported into the PHP realm: dynamic and interpreted language, short-lived objects... »
Giorgio Sironi

Domain-Driven Design in PHP
It must be web
Not compiled, but interpreted
Not statically typed, but dynamic
Generic(s) code
JavaScript, CSS, HTML...
jsTestDriver, Selenium, PHPUnit...
Domain Model Objects are in memory
For 2 milliseconds...
Public website?
Scalability
Security
Private application!
Maintainability
Business understanding
What is an application server?
From Domain Model to View Model
Data over the wire: JSON
What is concurrency?
Optimistic Locking
One aggregate at a time
Events flow to lazy-loaded Repositories
No SQL queries in the wild
No Active Record
It's OOP
class Vehicle { ...
private $plate;
/**
 * @var Operator
 */
private $operator;
class Dto_Leaf {
    private $fields = array();
}
Domain Model objects are stored into a relational database
An ORM is needed... Doctrine 2
Implements large part of JPA
Fights with Value Objects...
/**
 * @Entity
 */
class User {
    /**
     * @Column(type="datetime")
     */
    private $registration_date;
1. Use @Entity
2. Custom column-field conversion rule
/**
 * @Column(type="vat_rate")
 */
private $vat_rate;
3. Deconstruction with lifecycle hooks
/** 
 * @Column(type="integer")
 */
private $vat_rate_code;
/** 
 * @Column(type="integer")
 */
private $var_rate_percentage;
4. Serialization
/**
 * @Column(type=object)
 */
private $vat_rate;
but
VatCode::calculateTax($imponibile)
new VatCode(...);
What has changed?
Programmer's mindset
ORM details
Where do you keep your objects
Metaprogramming
but they are still organized as Aggregates
but even when one of them is generic, the layers are the same
There can be Clean Coders in the PHP world
but you can still have Value Objects
Thanks
Browser
Presentation Layer
Service Layer
Domain Model
We started from this:
Giorgio Sironi
Bachelor in Computer Engineering
Former Architect, now Advisor @ Allbus
Zone Leader @ DZone
The language is different
The language
The platform
The Domain Model
No JSON in my domain
Ext JS, Zend Framework...
I learned this from Gojko Adzic articles
Giorgio Sironi

Loading comments...

Please log in to add your comment.

Report abuse

More presentations by Giorgio Sironi

More prezis by author