Implementing DDD Concepts in PHP

Preview:

DESCRIPTION

A brief introduction to the concepts of domain driven design and their application to PHP.

Citation preview

Implementing DDD Concepts in PHP

Steve Rhoades

Panasonic Avionics

http://github.com/steverhoades@steverhoadeshttp://linkedin.com/in/steverhoadeshttp://stephenrhoades.com

Aleksey KhudyakovRoave, LLC

http://github.com/Xerkushttp://roave.com

Special Thanks

Marco Pivetta, Roave LLC http://github.com/ocramius

Overview• Ubiquitous Language• Bounded Context• Value Object• Entity• Repository• Collection• Mapper• Identity Map• Unit of Work• Services

What is Domain Driven Design

Collection of principles and patterns that help developers craft elegant systems

Ubiquitous Language

Allows for precise communication of ideas between stakeholders and developers

Developers should speak the language as well as include the language in the code base

Bounded Context

Keep varying business processes separated

Overlapping of business concerns should communicate through services

Value Object

An object that contains attributes but does not have an identity

Value Objects are Immutable

Don’t forget behaviors!

Entity

An entity is an object in your application that has an identity.

Anemic Entity anti-pattern

Look like Value Objects but have identity

Lack behavior

Repository

A segregated interface that utilizes the ubiquitous language to hide the infrastructure layer

Storage, Memory, Remote Service

Collections

Mapper (Data Mapper)

Used to pull Entity data from persistence

Developers can create custom Data Mappers without affecting the rest of the application

• Unit Test• MongoDB• Redis• MySQL• Oracle• Web Services• File System

Identity Map

Caches Entities in memory to ensure there is only one instance in memory at any given time

Martin FowlerP of EAA

READ THIS!

Services

Utilized when the natural processing on an Entity or a Value Object is no longer valid

Domain Services should not contain state

Application Services and Domain Services are often confused

Application Services orchestrate demands from a given use case or workflow

Application Services “should not” contain business logic will make calls to Domain and Infrastructure services as well as Entities

Helpful to think of an Application Service as a command object

Unit of Work(example of Application Service)

Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency

- Martin Fowler, P of EAA

Further Resources• Domain Driven Design, Eric Evans• Patterns of Enterprise Application Architecture,

Martin Fowler• Applying Domain-Driven Design and Patterns,

Jimmy Nilsson• Implementing Domain Driven Design, Vernon

Vaughn

Please Review

https://joind.in/9594

Recommended