SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
Principles of PHP Package Design
Lastminutetalk
Matthias Noback - PHP developer and consultant
AmsterdamPHP - 9/19/2013
Matthias Noback
Principles of OOD
Dutch developer
Consultancy, training, writing
Clean code, TDD
·
·
·
2/44
Micro versus macro design
Organizational units:
Classes
Packages (modules, components, bundles, ...)
·
·
3/44
Principles of class design
4/44
Principles of class design
The Single Responsibility Principle
A class should have one, and only one, reason to change
5/44
Principles of class design
The Open Closed Principle
You should be able to extend a classes behavior, without modifying it
6/44
Principles of class design
The Liskov Substitution Principle
Derived classes must be substitutable for their base classes
7/44
Principles of class design
The Interface Segregation Principle
Make fine grained interfaces that are client specific
8/44
Principles of class design
The Dependency Inversion Principle
Depend on abstractions, not on concretions
9/44
Principles of package design
10/44
Principles of package design
Cohesion
What to put inside packages?
Coupling
How to couple packages?
11/44
Cohesion principles
12/44
The Release Reuse Equivalency Principle
The granule of reuse is the granule of release
"A package as a product"
13/44
The Release Reuse Equivalency Principle
Version control
Package definition
Hosting
Auto-loading
BC
Marking breaks
Semantic versioning
Tags
Required files
Quality control
·
·
·
·
·
·
·
·
·
·
14/44
The Release Reuse Equivalency Principle
Example: ChargebeeAPI classes (irrelevant composer.json)
Example: HTMLPurify(old-school auto-loading)
Example: Codeception Silexmodule (custom VCS hosting)
15/44
The Common Closure Principle
Classes that change together are packaged together
Ask yourself which packages would change when:
The web framework changes
The persistence library changes
The application's features change
The business rules change
...
·
·
·
·
·
16/44
The Common Closure Principle
Classes that change together are packaged together
Example: FOSUserBundle- too much library code
Example: FOSRestBundleand JMSSerializerBundle- a dangerous alliance
17/44
The Common Reuse Principle
Classes that are used together are packaged together
If you use a class inside a package, you will (most likely) use (all) other classes
inside it too.
18/44
The Common Reuse Principle
Classes that are used together are packaged together
Example: FOSRestBundleand the QueryParamFetcher
Example: Monologand its handlers
Example: Asseticand its filters
Example: NelmioSecurityBundleand its listeners
19/44
Coupling principles
20/44
The Acyclic Dependencies Principle
The dependency graph of packages must have no cycles
Create a dependencies diagram:
clue/graph-composer
21/44
The Stable Dependencies Principle
Depend in the direction of stability
"Stability" equals "not easy to change" (versus volatility).
Hard to change packages should not depend on easy to change packages.
22/44
The Stable Dependencies Principle
Depend in the direction of stability
Dependencies between packages are dependencies by class:
Count number of dependencies out (C-out)
Count number of dependencies in (C-in)
I = C-out / (C-in + C-out)
23/44
The Stable Dependencies Principle
Depend in the direction of stability
E.g. 2 / (0 + 2) = 1(only out), so 1is very dependent, therefore instable
E.g. 0 / (3 + 0) = 0(only in), so 0is independent, therefore stable
24/44
The Stable Dependencies Principle
Depend in the direction of stability
Packages with more dependencies depend on packages with less dependencies.
These are less likely (because difficult) to change, since many other packages
depend on them.
25/44
The Stable Dependencies Principle
Depend in the direction of stability
Stable packages are called responsible (they should not be easy to change),
independent (only depended upon) packages.
Instable packages are called irresponsible (because easily changed) and
dependent (on more stable packages).
26/44
The Stable Abstractions Principle
Abstractness increases with stability
A package should be as abstract as it is stable.
A stable package (with less dependencies out than in), should have an equal
ratio of abstract versus total amount of classes.
27/44
The Stable Abstractions Principle
Abstractness increases with stability
Stable package: difficult to change. It has more dependencies in than out.
Given the Dependency Inversion Principle, packages will depend on other
packages because those contain abstract classes and interfaces, which adds
stability to their design.
28/44
The Stable Abstractions Principle
Abstractness increases with stability
A = C-abstract / (C-concrete + C-abstract)
No abstract classes, just concrete classes: A = 0
No concrete classes, just abstract classes: A = 1
29/44
The Stable Abstractions Principle
Abstractness increases with stability
Combine Iand Ain a graph.
30/44
The Stable Abstractions Principle
Abstractness increases with stability
When you plot these ratios you will see:
I = 0(stable) and A = 1(abstract) = (0, 1)(top-left corner)
I = 1(instable) and A = 0(concrete) = (1, 0)(bottom-right corner)
31/44
The Stable Abstractions Principle
Abstractness increases with stability
Everything in between should be in proportion.
A less stable package, should be also more concrete.
A more stable package, should also be more abstract.
32/44
The Stable Abstractions Principle
Abstractness increases with stability
On the other end of the spectrum are some strange packages:
I = 1(instable) and A = 1(abstract) = (1, 1)(top-right)
A package with no dependents, only dependencies, but very abstract
nonetheless.
I = 0(stable) and A = 0(concrete) = (0, 0)(bottom-left)
A package that has no dependencies, only dependents, and nevertheless has
only concrete classes.
33/44
The rule of three
34/44
The Rule of Three
From Facts and Fallacies of Software Engineering:
Therearetwo"rulesofthree"in[software]reuse:
Itisthreetimesasdifficulttobuildreusablecomponentsassingleuse
components,andareusablecomponentshouldbetriedoutinthreedifferent
applicationsbeforeitwillbesufficientlygeneraltoacceptintoareuse
library.
35/44
The Rule of Three
Effort
Project packages: 1:1
Written ony for this project (like modules for account management, blog, etc.).
36/44
The Rule of Three
Effort
Library package: 1:1or 3:2
For common needs, written for this project, but reusable in other projects.
37/44
The Rule of Three
Effort
Open sourced library package: 2:1
38/44
The Rule of Three
Effort
An entire reusable project (like Sylius): 3:1
(Or parts of it.). Within a well-known structure, offer end-to-end functionality,
while making it easy to extend/change behavior.
39/44
A Year With Symfony
About the book
40/44
41/44
A Year With Symfony
When you work with Symfony2:
You need to understand the framework very well
You need to be very good at dependency injection
You will need a good project structure
You need to do be very well aware of any possible security issues
You should develop for reusability
·
·
·
·
·
42/44
Raffle
A Year With Symfony
43/44
Thank you
twitter @matthiasnoback
www php-and-symfony.matthiasnoback.nl
github github.com/matthiasnoback
leanpub leanpub.com/a-year-with-symfony

Weitere ähnliche Inhalte

Andere mochten auch

MidwestPHP Symfony2 Internals
MidwestPHP Symfony2 InternalsMidwestPHP Symfony2 Internals
MidwestPHP Symfony2 Internals
Raul Fraile
 

Andere mochten auch (11)

MidwestPHP Symfony2 Internals
MidwestPHP Symfony2 InternalsMidwestPHP Symfony2 Internals
MidwestPHP Symfony2 Internals
 
Tipos de-datos-power-designer
Tipos de-datos-power-designerTipos de-datos-power-designer
Tipos de-datos-power-designer
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UK
 
Creating hypermedia APIs in a few minutes using the API Platform framework
Creating hypermedia APIs in a few minutes using the API Platform frameworkCreating hypermedia APIs in a few minutes using the API Platform framework
Creating hypermedia APIs in a few minutes using the API Platform framework
 
Symfony in microservice architecture
Symfony in microservice architectureSymfony in microservice architecture
Symfony in microservice architecture
 
Caja de Herramientas para un Equipo Scrum de Alto Rendimiento
Caja de Herramientas para un Equipo Scrum de Alto RendimientoCaja de Herramientas para un Equipo Scrum de Alto Rendimiento
Caja de Herramientas para un Equipo Scrum de Alto Rendimiento
 
Marketing - Packaging Project CBSE
Marketing - Packaging Project CBSEMarketing - Packaging Project CBSE
Marketing - Packaging Project CBSE
 
Packaging project
Packaging project Packaging project
Packaging project
 
Packaging design ppt
Packaging design pptPackaging design ppt
Packaging design ppt
 
Packaging & labeling in food industries
Packaging & labeling in food industriesPackaging & labeling in food industries
Packaging & labeling in food industries
 
Principles and Practices in Continuous Deployment at Etsy
Principles and Practices in Continuous Deployment at EtsyPrinciples and Practices in Continuous Deployment at Etsy
Principles and Practices in Continuous Deployment at Etsy
 

Ähnlich wie Principles of PHP Package Design (for AmsterdamPHP)

OO design principle
OO design principleOO design principle
OO design principle
Li-Wei Cheng
 
Chapter 4Optimization Manifesto OurMission and Our Unif.docx
Chapter 4Optimization Manifesto OurMission and Our Unif.docxChapter 4Optimization Manifesto OurMission and Our Unif.docx
Chapter 4Optimization Manifesto OurMission and Our Unif.docx
christinemaritza
 
Loop Fusion for Memory Space Optimization
Loop Fusion for Memory Space OptimizationLoop Fusion for Memory Space Optimization
Loop Fusion for Memory Space Optimization
tmusabbir
 

Ähnlich wie Principles of PHP Package Design (for AmsterdamPHP) (20)

Ooad presentation package_design
Ooad presentation package_designOoad presentation package_design
Ooad presentation package_design
 
uml reference package_diagram
uml reference package_diagramuml reference package_diagram
uml reference package_diagram
 
Principles of PHP Package Design - DomCode, first monthly meeting
Principles of PHP Package Design - DomCode, first monthly meetingPrinciples of PHP Package Design - DomCode, first monthly meeting
Principles of PHP Package Design - DomCode, first monthly meeting
 
2016-04-22: Beyond SOLID: The Package Principles
2016-04-22: Beyond SOLID: The Package Principles2016-04-22: Beyond SOLID: The Package Principles
2016-04-22: Beyond SOLID: The Package Principles
 
PMSE pdf
PMSE pdfPMSE pdf
PMSE pdf
 
OO design principle
OO design principleOO design principle
OO design principle
 
Java Access Specifier
Java Access SpecifierJava Access Specifier
Java Access Specifier
 
Soild principles
Soild principlesSoild principles
Soild principles
 
Micro Anti-patterns in Java Code
Micro Anti-patterns in Java CodeMicro Anti-patterns in Java Code
Micro Anti-patterns in Java Code
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Classes & Interfaces
Classes & InterfacesClasses & Interfaces
Classes & Interfaces
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
 
Chapter 1 :
Chapter 1 : Chapter 1 :
Chapter 1 :
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Oop principles
Oop principlesOop principles
Oop principles
 
chapter 5 concepts of object oriented programming
chapter 5 concepts of object oriented programmingchapter 5 concepts of object oriented programming
chapter 5 concepts of object oriented programming
 
Chapter 4Optimization Manifesto OurMission and Our Unif.docx
Chapter 4Optimization Manifesto OurMission and Our Unif.docxChapter 4Optimization Manifesto OurMission and Our Unif.docx
Chapter 4Optimization Manifesto OurMission and Our Unif.docx
 
Core java questions
Core java questionsCore java questions
Core java questions
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Loop Fusion for Memory Space Optimization
Loop Fusion for Memory Space OptimizationLoop Fusion for Memory Space Optimization
Loop Fusion for Memory Space Optimization
 

Mehr von Matthias Noback

Advanced web application architecture - PHP Barcelona
Advanced web application architecture  - PHP BarcelonaAdvanced web application architecture  - PHP Barcelona
Advanced web application architecture - PHP Barcelona
Matthias Noback
 
A testing strategy for hexagonal applications
A testing strategy for hexagonal applicationsA testing strategy for hexagonal applications
A testing strategy for hexagonal applications
Matthias Noback
 

Mehr von Matthias Noback (20)

Rector fireside chat - PHPMiNDS meetup
Rector fireside chat - PHPMiNDS meetupRector fireside chat - PHPMiNDS meetup
Rector fireside chat - PHPMiNDS meetup
 
Service abstractions - Part 1: Queries
Service abstractions - Part 1: QueriesService abstractions - Part 1: Queries
Service abstractions - Part 1: Queries
 
Hexagonal Symfony - SymfonyCon Amsterdam 2019
Hexagonal Symfony - SymfonyCon Amsterdam 2019Hexagonal Symfony - SymfonyCon Amsterdam 2019
Hexagonal Symfony - SymfonyCon Amsterdam 2019
 
Advanced web application architecture - PHP Barcelona
Advanced web application architecture  - PHP BarcelonaAdvanced web application architecture  - PHP Barcelona
Advanced web application architecture - PHP Barcelona
 
A testing strategy for hexagonal applications
A testing strategy for hexagonal applicationsA testing strategy for hexagonal applications
A testing strategy for hexagonal applications
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
 
DPC 2019, Amsterdam: Beyond design patterns and principles - writing good OO ...
DPC 2019, Amsterdam: Beyond design patterns and principles - writing good OO ...DPC 2019, Amsterdam: Beyond design patterns and principles - writing good OO ...
DPC 2019, Amsterdam: Beyond design patterns and principles - writing good OO ...
 
Layers, ports and adapters
Layers, ports and adaptersLayers, ports and adapters
Layers, ports and adapters
 
Beyond design principles and patterns (muCon 2019 edition)
Beyond design principles and patterns (muCon 2019 edition)Beyond design principles and patterns (muCon 2019 edition)
Beyond design principles and patterns (muCon 2019 edition)
 
Brutal refactoring, lying code, the Churn, and other emotional stories from L...
Brutal refactoring, lying code, the Churn, and other emotional stories from L...Brutal refactoring, lying code, the Churn, and other emotional stories from L...
Brutal refactoring, lying code, the Churn, and other emotional stories from L...
 
Advanced web application architecture Way2Web
Advanced web application architecture Way2WebAdvanced web application architecture Way2Web
Advanced web application architecture Way2Web
 
Brutal refactoring, lying code, the Churn, and other emotional stories from L...
Brutal refactoring, lying code, the Churn, and other emotional stories from L...Brutal refactoring, lying code, the Churn, and other emotional stories from L...
Brutal refactoring, lying code, the Churn, and other emotional stories from L...
 
Beyond Design Principles and Patterns
Beyond Design Principles and PatternsBeyond Design Principles and Patterns
Beyond Design Principles and Patterns
 
Building Autonomous Services
Building Autonomous ServicesBuilding Autonomous Services
Building Autonomous Services
 
Advanced Application Architecture Symfony Live Berlin 2018
Advanced Application Architecture Symfony Live Berlin 2018Advanced Application Architecture Symfony Live Berlin 2018
Advanced Application Architecture Symfony Live Berlin 2018
 
Designing for Autonomy
Designing for AutonomyDesigning for Autonomy
Designing for Autonomy
 
Docker workshop
Docker workshopDocker workshop
Docker workshop
 
Docker swarm workshop
Docker swarm workshopDocker swarm workshop
Docker swarm workshop
 
Docker compose workshop
Docker compose workshopDocker compose workshop
Docker compose workshop
 
Building autonomous services
Building autonomous servicesBuilding autonomous services
Building autonomous services
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Principles of PHP Package Design (for AmsterdamPHP)

  • 1. Principles of PHP Package Design Lastminutetalk Matthias Noback - PHP developer and consultant AmsterdamPHP - 9/19/2013
  • 2. Matthias Noback Principles of OOD Dutch developer Consultancy, training, writing Clean code, TDD · · · 2/44
  • 3. Micro versus macro design Organizational units: Classes Packages (modules, components, bundles, ...) · · 3/44
  • 4. Principles of class design 4/44
  • 5. Principles of class design The Single Responsibility Principle A class should have one, and only one, reason to change 5/44
  • 6. Principles of class design The Open Closed Principle You should be able to extend a classes behavior, without modifying it 6/44
  • 7. Principles of class design The Liskov Substitution Principle Derived classes must be substitutable for their base classes 7/44
  • 8. Principles of class design The Interface Segregation Principle Make fine grained interfaces that are client specific 8/44
  • 9. Principles of class design The Dependency Inversion Principle Depend on abstractions, not on concretions 9/44
  • 10. Principles of package design 10/44
  • 11. Principles of package design Cohesion What to put inside packages? Coupling How to couple packages? 11/44
  • 13. The Release Reuse Equivalency Principle The granule of reuse is the granule of release "A package as a product" 13/44
  • 14. The Release Reuse Equivalency Principle Version control Package definition Hosting Auto-loading BC Marking breaks Semantic versioning Tags Required files Quality control · · · · · · · · · · 14/44
  • 15. The Release Reuse Equivalency Principle Example: ChargebeeAPI classes (irrelevant composer.json) Example: HTMLPurify(old-school auto-loading) Example: Codeception Silexmodule (custom VCS hosting) 15/44
  • 16. The Common Closure Principle Classes that change together are packaged together Ask yourself which packages would change when: The web framework changes The persistence library changes The application's features change The business rules change ... · · · · · 16/44
  • 17. The Common Closure Principle Classes that change together are packaged together Example: FOSUserBundle- too much library code Example: FOSRestBundleand JMSSerializerBundle- a dangerous alliance 17/44
  • 18. The Common Reuse Principle Classes that are used together are packaged together If you use a class inside a package, you will (most likely) use (all) other classes inside it too. 18/44
  • 19. The Common Reuse Principle Classes that are used together are packaged together Example: FOSRestBundleand the QueryParamFetcher Example: Monologand its handlers Example: Asseticand its filters Example: NelmioSecurityBundleand its listeners 19/44
  • 21. The Acyclic Dependencies Principle The dependency graph of packages must have no cycles Create a dependencies diagram: clue/graph-composer 21/44
  • 22. The Stable Dependencies Principle Depend in the direction of stability "Stability" equals "not easy to change" (versus volatility). Hard to change packages should not depend on easy to change packages. 22/44
  • 23. The Stable Dependencies Principle Depend in the direction of stability Dependencies between packages are dependencies by class: Count number of dependencies out (C-out) Count number of dependencies in (C-in) I = C-out / (C-in + C-out) 23/44
  • 24. The Stable Dependencies Principle Depend in the direction of stability E.g. 2 / (0 + 2) = 1(only out), so 1is very dependent, therefore instable E.g. 0 / (3 + 0) = 0(only in), so 0is independent, therefore stable 24/44
  • 25. The Stable Dependencies Principle Depend in the direction of stability Packages with more dependencies depend on packages with less dependencies. These are less likely (because difficult) to change, since many other packages depend on them. 25/44
  • 26. The Stable Dependencies Principle Depend in the direction of stability Stable packages are called responsible (they should not be easy to change), independent (only depended upon) packages. Instable packages are called irresponsible (because easily changed) and dependent (on more stable packages). 26/44
  • 27. The Stable Abstractions Principle Abstractness increases with stability A package should be as abstract as it is stable. A stable package (with less dependencies out than in), should have an equal ratio of abstract versus total amount of classes. 27/44
  • 28. The Stable Abstractions Principle Abstractness increases with stability Stable package: difficult to change. It has more dependencies in than out. Given the Dependency Inversion Principle, packages will depend on other packages because those contain abstract classes and interfaces, which adds stability to their design. 28/44
  • 29. The Stable Abstractions Principle Abstractness increases with stability A = C-abstract / (C-concrete + C-abstract) No abstract classes, just concrete classes: A = 0 No concrete classes, just abstract classes: A = 1 29/44
  • 30. The Stable Abstractions Principle Abstractness increases with stability Combine Iand Ain a graph. 30/44
  • 31. The Stable Abstractions Principle Abstractness increases with stability When you plot these ratios you will see: I = 0(stable) and A = 1(abstract) = (0, 1)(top-left corner) I = 1(instable) and A = 0(concrete) = (1, 0)(bottom-right corner) 31/44
  • 32. The Stable Abstractions Principle Abstractness increases with stability Everything in between should be in proportion. A less stable package, should be also more concrete. A more stable package, should also be more abstract. 32/44
  • 33. The Stable Abstractions Principle Abstractness increases with stability On the other end of the spectrum are some strange packages: I = 1(instable) and A = 1(abstract) = (1, 1)(top-right) A package with no dependents, only dependencies, but very abstract nonetheless. I = 0(stable) and A = 0(concrete) = (0, 0)(bottom-left) A package that has no dependencies, only dependents, and nevertheless has only concrete classes. 33/44
  • 34. The rule of three 34/44
  • 35. The Rule of Three From Facts and Fallacies of Software Engineering: Therearetwo"rulesofthree"in[software]reuse: Itisthreetimesasdifficulttobuildreusablecomponentsassingleuse components,andareusablecomponentshouldbetriedoutinthreedifferent applicationsbeforeitwillbesufficientlygeneraltoacceptintoareuse library. 35/44
  • 36. The Rule of Three Effort Project packages: 1:1 Written ony for this project (like modules for account management, blog, etc.). 36/44
  • 37. The Rule of Three Effort Library package: 1:1or 3:2 For common needs, written for this project, but reusable in other projects. 37/44
  • 38. The Rule of Three Effort Open sourced library package: 2:1 38/44
  • 39. The Rule of Three Effort An entire reusable project (like Sylius): 3:1 (Or parts of it.). Within a well-known structure, offer end-to-end functionality, while making it easy to extend/change behavior. 39/44
  • 40. A Year With Symfony About the book 40/44
  • 41. 41/44
  • 42. A Year With Symfony When you work with Symfony2: You need to understand the framework very well You need to be very good at dependency injection You will need a good project structure You need to do be very well aware of any possible security issues You should develop for reusability · · · · · 42/44
  • 43. Raffle A Year With Symfony 43/44
  • 44. Thank you twitter @matthiasnoback www php-and-symfony.matthiasnoback.nl github github.com/matthiasnoback leanpub leanpub.com/a-year-with-symfony