implementing ddd concepts in php

56
Implementing DDD Concepts in PHP Steve Rhoades Panasonic Avionics http://github.com/ steverhoades @steverhoades http://linkedin.com/in/ steverhoades http://stephenrhoades.com Aleksey Khudyakov Roave, LLC http://github.com/Xerkus http://roave.com Special Thanks Marco Pivetta, Roave LLC http://github.com/ocramius

Upload: steve-rhoades

Post on 05-Dec-2014

3.238 views

Category:

Technology


7 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Implementing DDD Concepts in PHP

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

Page 2: Implementing DDD Concepts in PHP

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

Page 3: Implementing DDD Concepts in PHP

What is Domain Driven Design

Page 4: Implementing DDD Concepts in PHP

Collection of principles and patterns that help developers craft elegant systems

Page 5: Implementing DDD Concepts in PHP

Ubiquitous Language

Page 6: Implementing DDD Concepts in PHP

Allows for precise communication of ideas between stakeholders and developers

Page 7: Implementing DDD Concepts in PHP

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

Page 8: Implementing DDD Concepts in PHP
Page 9: Implementing DDD Concepts in PHP

Bounded Context

Page 10: Implementing DDD Concepts in PHP

Keep varying business processes separated

Page 11: Implementing DDD Concepts in PHP

Overlapping of business concerns should communicate through services

Page 12: Implementing DDD Concepts in PHP

Value Object

Page 13: Implementing DDD Concepts in PHP

An object that contains attributes but does not have an identity

Page 14: Implementing DDD Concepts in PHP

Value Objects are Immutable

Page 15: Implementing DDD Concepts in PHP
Page 16: Implementing DDD Concepts in PHP

Don’t forget behaviors!

Page 17: Implementing DDD Concepts in PHP
Page 18: Implementing DDD Concepts in PHP

Entity

Page 19: Implementing DDD Concepts in PHP

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

Page 20: Implementing DDD Concepts in PHP

Anemic Entity anti-pattern

Page 21: Implementing DDD Concepts in PHP

Look like Value Objects but have identity

Page 22: Implementing DDD Concepts in PHP

Lack behavior

Page 23: Implementing DDD Concepts in PHP
Page 24: Implementing DDD Concepts in PHP
Page 25: Implementing DDD Concepts in PHP

Repository

Page 26: Implementing DDD Concepts in PHP

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

Page 27: Implementing DDD Concepts in PHP

Storage, Memory, Remote Service

Page 28: Implementing DDD Concepts in PHP
Page 29: Implementing DDD Concepts in PHP
Page 30: Implementing DDD Concepts in PHP
Page 31: Implementing DDD Concepts in PHP

Collections

Page 32: Implementing DDD Concepts in PHP
Page 33: Implementing DDD Concepts in PHP
Page 34: Implementing DDD Concepts in PHP

Mapper (Data Mapper)

Page 35: Implementing DDD Concepts in PHP

Used to pull Entity data from persistence

Page 36: Implementing DDD Concepts in PHP

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

Page 37: Implementing DDD Concepts in PHP

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

Page 38: Implementing DDD Concepts in PHP
Page 39: Implementing DDD Concepts in PHP
Page 40: Implementing DDD Concepts in PHP

Identity Map

Page 41: Implementing DDD Concepts in PHP

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

Page 42: Implementing DDD Concepts in PHP

Martin FowlerP of EAA

READ THIS!

Page 43: Implementing DDD Concepts in PHP
Page 44: Implementing DDD Concepts in PHP

Services

Page 45: Implementing DDD Concepts in PHP

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

Page 46: Implementing DDD Concepts in PHP

Domain Services should not contain state

Page 47: Implementing DDD Concepts in PHP
Page 48: Implementing DDD Concepts in PHP

Application Services and Domain Services are often confused

Page 49: Implementing DDD Concepts in PHP

Application Services orchestrate demands from a given use case or workflow

Page 50: Implementing DDD Concepts in PHP

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

Page 51: Implementing DDD Concepts in PHP

Helpful to think of an Application Service as a command object

Page 52: Implementing DDD Concepts in PHP

Unit of Work(example of Application Service)

Page 53: Implementing DDD Concepts in PHP

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

Page 54: Implementing DDD Concepts in PHP
Page 55: Implementing DDD Concepts in PHP

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

Page 56: Implementing DDD Concepts in PHP

Please Review

https://joind.in/9594