SlideShare a Scribd company logo
BEYOND DESIGN PATTERNS
& PRINCIPLES
WRITING GOOD OO CODE
Before?
Matthias Noback
@matthiasnoback
My goals
To give you some vocabulary for code discussions
and reviews

To bring back our focus to the basic ideas behind
OOP
Abstract factory
Builder
Factory method
Singleton
Adapter
Bridge
Composite
Facade
Proxy
Chain of responsibility
Command
Mediator
Strategy
Observer
Single responsibility principle
Open/closed principle
Liskov substitution principle
Interface segregation principle
Dependency inversion principle
EVERYTHING IS AN OBJECT
Alan Kay
Strings
Integers Booleans
Floats
Beyond Design Patterns and Principles - PHPBenelux 2017
Beyond Design Patterns and Principles - PHPBenelux 2017
Domain concepts
Use cases
Infra-stuff
Objects introduce meaning
Strings
Email
addresses
OBJECTS ENCAPSULATE
STATE AND BEHAVIOR
enclose
a = …
b = …
behaviorA()
behaviorB()
Behavior
State
Primitive
values
Services
Entities
Value
objects
Anemic
domain
objects
Find a balance
SERVICES SHOULD BE
MODELLED AS FUNCTIONS
behaviorA()
behaviorB()
somewhatUnrelated()
!!!
somewhatUnrelated()
behaviorA()
behaviorB()Because: SRP
behaviorA()
behaviorB()
behaviorB()
Because: ISP
behaviorA()
Single-method classes
~=
Functions
http://blog.ploeh.dk/...
Functions
Naturally stateless
class TheClass
{
public doSomething(...)
{
check pre-conditions
happy path
handle failure
check post-conditions
}
}
Simpler design, easier to test
The unit is smaller
Small number of possible execution paths
No unexpected changes in behavior
OBJECTS SHOULD BE EXPLICIT
ABOUT SIDE-EFFECTS
class RegisterUser
{
private repository
private logger
public void register(name) {
repository.add(new User(name));
logger.log(“New user added”);
}
}
Side effects!
function registerUser(name, repository, logger)
{
repository.add(new User(name));
logger.log(“New user added”);
}
logger
log()
repository
add()
add()
log()
RegisterUser
INJECTED SERVICES SHOULD BE
SINGLE-METHOD OBJECTS TOO
function registerUserFactory(repository, logger)
{
return function(name) {
repository.add(new User(name));
logger.log(“New user added”);
}
}
registerUser = registerUserFactory(
repository,
logger
);
registerUser(“Matthias”);
No service locators
serviceLocator.get(‘service id’).method()
Inject this
object instead!
No train wrecks
someService.getOtherService.doSomething()
Inject this
object instead!
Inject only single-method
services
Side-effects will be explicit
Responsibilities will be more explicit
Dependencies will be easier to mock
OBJECTS SHOULD ONLY
EXIST IN A VALID STATE
condition
?
construct()
Something is
not right!!!?
behaviorB()
First call
behaviorA()!!!?
canCallBehaviorB()
behaviorB()
Yes
Tell, don’t ask
Anemic domain
model
?
YesValidatorisValid( )
How to prevent this?
?
What about…
changeState( , , )
?
ONLY VALID VALUES SHOULD
CROSS OBJECT BOUNDARIES
Crossing boundaries
Arguments
Return values,
Exceptions
changeState(...) {
check pre-conditions
...
check post-conditions
}
changeState()
doSomething()
getSomething()
construct()
Advantages of always-valid
objects
Easy to debug
Easy to refactor
Easy to reason about
ALMOST ALL OBJECTS
SHOULD BE IMMUTABLE
unable to be changed
Beyond Design Patterns and Principles - PHPBenelux 2017
changeState( )
??????
!!!!!!!
changeState( )
Advantages of immutability
Clear distinction between using state and changing state
Pass on objects without worrying
Use objects without worrying
Easier to reason about
OBJECTS SHOULD COMMUNICATE
USING WELL-DEFINED MESSAGES
“Alan Kay”
Beyond Design Patterns and Principles - PHPBenelux 2017
call( )
Calling methods
==
Sending messages
Receiving return values
==
Receiving messages
Catching exceptions
==
Receiving messages
Command
Query Document
Command
Query Document
public void doSomething(...) {
...
}
public [return-type] getSomething(...) {
return ...
}
CQS: command-query
separation
Asking for information doesn’t change observable state
EVERYTHING IS AN OBJECT
YOUR APPLICATION TOO!
Sort of…
“I thought of objects being like biological cells and/
or individual computers on a network, only able to
communicate with messages […]”
Alan Kay
a = …
b = …
behaviorA()
behaviorB()
a = …
b = …
behaviorA()
behaviorB()
Beyond Design Patterns and Principles - PHPBenelux 2017
State should always be valid
Command
Command
Command
Apply CQS
Command
Query
Prefer immutability
Query
Document
This design emerges
Your application has side-
effects
Filesystem
Keyboard
Screen
Network
Apply hexagonal
architecture
IN WHICH WAYS IS YOUR
APPLICATION NOT AN OBJECT?
Beyond Design Patterns and Principles - PHPBenelux 2017
Beyond Design Patterns and Principles - PHPBenelux 2017
Beyond Design Patterns and Principles - PHPBenelux 2017
???
Some suggestions
Write the serialization code yourself
The object’s design always comes first
Don’t let tools mess with object encapsulation
Also…
Try Event Sourcing
CONCLUSION
EVERYTHING IS AN OBJECT
OBJECTS ENCAPSULATE STATE AND BEHAVIOR
SERVICES SHOULD BE MODELLED AS FUNCTIONS
OBJECTS SHOULD BE EXPLICIT ABOUT SIDE-EFFECTS
ALMOST ALL OBJECTS SHOULD BE IMMUTABLE
TREAT YOUR APPLICATION AS AN OBJECT

(AND VICE VERSA)
ONLY VALID VALUES SHOULD CROSS OBJECT BOUNDARIES
OBJECTS SHOULD ONLY EXIST IN A VALID STATE
OBJECTS SHOULD COMMUNICATE USING WELL-DEFINED MESSAGES
CQRS & event sourcing in the wild
Michiel Rook
Extremely defensive PHP
Marco Pivetta
The true value of objects
Stijn Vannieuwenhuyse
Kafka will get the message
across, guaranteed
David Zuelke

More Related Content

What's hot (20)

PDF
Breaking Dependencies to Allow Unit Testing
Steven Smith
 
PPTX
Introducing Domain Driven Design - codemash
Steven Smith
 
PPTX
LINQ in C#
Basant Medhat
 
PPTX
Entity framework
icubesystem
 
PDF
Modularity and Domain Driven Design - A killer combination - T De Wolf & S va...
mfrancis
 
PPTX
Understanding LINQ in C#
MD. Shohag Mia
 
PDF
Design patterns - Proxy & Composite
Sarath C
 
PPTX
Introduction to JSX
Micah Wood
 
PPTX
To Lombok or not to Lombok | J-Fall 2019
Kaya Weers
 
PPTX
Ef code first
ZealousysDev
 
PDF
Solid principles, Design Patterns, and Domain Driven Design
Irwansyah Irwansyah
 
PPTX
Design Patterns - 03 Composite and Flyweight Pattern
eprafulla
 
PPTX
Entity Framework 4
Stefano Paluello
 
PPTX
Building maintainable web apps with Angular MS TechDays 2017
Erik van Appeldoorn
 
PPTX
Entity framework code first
Confiz
 
KEY
Introducing the Entity Framework
LearnNowOnline
 
PDF
Learn Entity Framework in a day with Code First, Model First and Database First
Jibran Rasheed Khan
 
PDF
Clean architecture with ddd layering in php
Leonardo Proietti
 
PPT
Lambdas
malliksunkara
 
PPTX
Scope demystified - AngularJS
Sumanth krishna
 
Breaking Dependencies to Allow Unit Testing
Steven Smith
 
Introducing Domain Driven Design - codemash
Steven Smith
 
LINQ in C#
Basant Medhat
 
Entity framework
icubesystem
 
Modularity and Domain Driven Design - A killer combination - T De Wolf & S va...
mfrancis
 
Understanding LINQ in C#
MD. Shohag Mia
 
Design patterns - Proxy & Composite
Sarath C
 
Introduction to JSX
Micah Wood
 
To Lombok or not to Lombok | J-Fall 2019
Kaya Weers
 
Ef code first
ZealousysDev
 
Solid principles, Design Patterns, and Domain Driven Design
Irwansyah Irwansyah
 
Design Patterns - 03 Composite and Flyweight Pattern
eprafulla
 
Entity Framework 4
Stefano Paluello
 
Building maintainable web apps with Angular MS TechDays 2017
Erik van Appeldoorn
 
Entity framework code first
Confiz
 
Introducing the Entity Framework
LearnNowOnline
 
Learn Entity Framework in a day with Code First, Model First and Database First
Jibran Rasheed Khan
 
Clean architecture with ddd layering in php
Leonardo Proietti
 
Lambdas
malliksunkara
 
Scope demystified - AngularJS
Sumanth krishna
 

Viewers also liked (20)

PDF
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
Matthias Noback
 
PDF
A recommendation engine for your php application
Michele Orselli
 
PDF
Please understand me
Matthias Noback
 
PDF
PHP Benelux 2017 - Caching The Right Way
André Rømcke
 
PPTX
Php extensions
Elizabeth Smith
 
PDF
SunshinePHP 2017 - Making the most out of MySQL
Gabriela Ferrara
 
PPTX
Debugging Effectively - SunshinePHP 2017
Colin O'Dell
 
PDF
Learn To Test Like A Grumpy Programmer - 3 hour workshop
chartjes
 
PDF
Programming with Cmdr. Chris Hadfield
Matthias Noback
 
PPTX
Debugging Effectively - PHP UK 2017
Colin O'Dell
 
PDF
PHP UK 2017 - Don't Lose Sleep - Secure Your REST
Adam Englander
 
PPTX
Docker for Developers - Sunshine PHP
Chris Tankersley
 
PDF
Beyond design patterns phpnw14
Anthony Ferrara
 
PDF
Silo-Based Architectures for High Availability Applications @CodeCampCluj
Tekkie Consulting
 
PDF
Integrating Bounded Contexts - Mini-workshop
Matthias Noback
 
PPT
Anti Corruption Layers
Marjan Nikolovski
 
PDF
Mejora tus retrospectivas
Juanma Gómez
 
PDF
What is CSP Fast Pass?
Carlton Nettleton
 
PDF
contratos agiles 2.1
Proyectalis / Improvement21
 
PDF
La paradoja de la eficiencia
Pablo Lischinsky
 
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
Matthias Noback
 
A recommendation engine for your php application
Michele Orselli
 
Please understand me
Matthias Noback
 
PHP Benelux 2017 - Caching The Right Way
André Rømcke
 
Php extensions
Elizabeth Smith
 
SunshinePHP 2017 - Making the most out of MySQL
Gabriela Ferrara
 
Debugging Effectively - SunshinePHP 2017
Colin O'Dell
 
Learn To Test Like A Grumpy Programmer - 3 hour workshop
chartjes
 
Programming with Cmdr. Chris Hadfield
Matthias Noback
 
Debugging Effectively - PHP UK 2017
Colin O'Dell
 
PHP UK 2017 - Don't Lose Sleep - Secure Your REST
Adam Englander
 
Docker for Developers - Sunshine PHP
Chris Tankersley
 
Beyond design patterns phpnw14
Anthony Ferrara
 
Silo-Based Architectures for High Availability Applications @CodeCampCluj
Tekkie Consulting
 
Integrating Bounded Contexts - Mini-workshop
Matthias Noback
 
Anti Corruption Layers
Marjan Nikolovski
 
Mejora tus retrospectivas
Juanma Gómez
 
What is CSP Fast Pass?
Carlton Nettleton
 
contratos agiles 2.1
Proyectalis / Improvement21
 
La paradoja de la eficiencia
Pablo Lischinsky
 
Ad

Similar to Beyond Design Patterns and Principles - PHPBenelux 2017 (20)

PDF
DPC 2019, Amsterdam: Beyond design patterns and principles - writing good OO ...
Matthias Noback
 
PDF
Beyond design principles and patterns (muCon 2019 edition)
Matthias Noback
 
PDF
Beyond Design Principles and Patterns
Matthias Noback
 
PPTX
Clean code
Simon Sönnby
 
PDF
The Open Closed Principle - Part 1 - The Original Version
Philip Schwarz
 
PDF
The Open-Closed Principle - the Original Version and the Contemporary Version
Philip Schwarz
 
PPTX
Clean code quotes - Citações e provocações
André de Fontana Ignacio
 
PPTX
CQRS: Command/Query Responsibility Segregation
Brian Ritchie
 
PPTX
From Good to SOLID: How to become a better PHP developer
Katerina Trajchevska
 
PPTX
Object Oriented, Design patterns and data modelling worshop
Mohammad Shawahneh
 
PDF
Object Oriented Design Principles
Thang Tran Duc
 
PPTX
Improving the Quality of Existing Software
Steven Smith
 
PPTX
Object Oriented Design SOLID Principles
rainynovember12
 
PPTX
Improving The Quality of Existing Software
Steven Smith
 
PPTX
Introduction to Software - Coder Forge - John Mulhall
John Mulhall
 
PDF
Twins: OOP and FP
RichardWarburton
 
PDF
Reviewing OOP Design patterns
Olivier Bacs
 
KEY
SOLID Design Principles
Samuel Breed
 
PPTX
The good, the bad and the SOLID
Frikkie van Biljon
 
PPT
Ood and solid principles
Avinash Kadam
 
DPC 2019, Amsterdam: Beyond design patterns and principles - writing good OO ...
Matthias Noback
 
Beyond design principles and patterns (muCon 2019 edition)
Matthias Noback
 
Beyond Design Principles and Patterns
Matthias Noback
 
Clean code
Simon Sönnby
 
The Open Closed Principle - Part 1 - The Original Version
Philip Schwarz
 
The Open-Closed Principle - the Original Version and the Contemporary Version
Philip Schwarz
 
Clean code quotes - Citações e provocações
André de Fontana Ignacio
 
CQRS: Command/Query Responsibility Segregation
Brian Ritchie
 
From Good to SOLID: How to become a better PHP developer
Katerina Trajchevska
 
Object Oriented, Design patterns and data modelling worshop
Mohammad Shawahneh
 
Object Oriented Design Principles
Thang Tran Duc
 
Improving the Quality of Existing Software
Steven Smith
 
Object Oriented Design SOLID Principles
rainynovember12
 
Improving The Quality of Existing Software
Steven Smith
 
Introduction to Software - Coder Forge - John Mulhall
John Mulhall
 
Twins: OOP and FP
RichardWarburton
 
Reviewing OOP Design patterns
Olivier Bacs
 
SOLID Design Principles
Samuel Breed
 
The good, the bad and the SOLID
Frikkie van Biljon
 
Ood and solid principles
Avinash Kadam
 
Ad

More from Matthias Noback (20)

PDF
Rector fireside chat - PHPMiNDS meetup
Matthias Noback
 
PDF
Service abstractions - Part 1: Queries
Matthias Noback
 
PDF
Hexagonal Symfony - SymfonyCon Amsterdam 2019
Matthias Noback
 
PDF
Advanced web application architecture - PHP Barcelona
Matthias Noback
 
PDF
A testing strategy for hexagonal applications
Matthias Noback
 
PDF
Advanced web application architecture - Talk
Matthias Noback
 
PDF
Layers, ports and adapters
Matthias Noback
 
PDF
Brutal refactoring, lying code, the Churn, and other emotional stories from L...
Matthias Noback
 
PDF
Advanced web application architecture Way2Web
Matthias Noback
 
PDF
Brutal refactoring, lying code, the Churn, and other emotional stories from L...
Matthias Noback
 
PDF
Building Autonomous Services
Matthias Noback
 
PDF
Advanced Application Architecture Symfony Live Berlin 2018
Matthias Noback
 
PDF
Designing for Autonomy
Matthias Noback
 
PDF
Docker workshop
Matthias Noback
 
PDF
Docker swarm workshop
Matthias Noback
 
PDF
Docker compose workshop
Matthias Noback
 
PDF
Building autonomous services
Matthias Noback
 
PDF
Designing for autonomy
Matthias Noback
 
PDF
Continously delivering containerized microservices
Matthias Noback
 
PDF
Apprendre le français
Matthias Noback
 
Rector fireside chat - PHPMiNDS meetup
Matthias Noback
 
Service abstractions - Part 1: Queries
Matthias Noback
 
Hexagonal Symfony - SymfonyCon Amsterdam 2019
Matthias Noback
 
Advanced web application architecture - PHP Barcelona
Matthias Noback
 
A testing strategy for hexagonal applications
Matthias Noback
 
Advanced web application architecture - Talk
Matthias Noback
 
Layers, ports and adapters
Matthias Noback
 
Brutal refactoring, lying code, the Churn, and other emotional stories from L...
Matthias Noback
 
Advanced web application architecture Way2Web
Matthias Noback
 
Brutal refactoring, lying code, the Churn, and other emotional stories from L...
Matthias Noback
 
Building Autonomous Services
Matthias Noback
 
Advanced Application Architecture Symfony Live Berlin 2018
Matthias Noback
 
Designing for Autonomy
Matthias Noback
 
Docker workshop
Matthias Noback
 
Docker swarm workshop
Matthias Noback
 
Docker compose workshop
Matthias Noback
 
Building autonomous services
Matthias Noback
 
Designing for autonomy
Matthias Noback
 
Continously delivering containerized microservices
Matthias Noback
 
Apprendre le français
Matthias Noback
 

Recently uploaded (20)

PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 

Beyond Design Patterns and Principles - PHPBenelux 2017