SlideShare a Scribd company logo
Principles of Package Design
How to create cohesive, stable packages
Matthias Noback
Writing
A Year With Symfony
leanpub.com/a-year-with-symfony
Tight coupling
What we do
Packages
many different kinds
Class design
Package design
Nothing?
butunclebob.com
Principles of Package Design
leanpub.com/principles-of-package-design
Package design
Cohesion
Package design
Coupling
A - Cohesion principles
Perspective: the package in isolation
!
1 - The Release Reuse Equivalence Principle
The granule of reuse is the granule of release
1 - The Release Reuse Equivalence Principle
• Version control and hosting
• Composer package definition
• Meta-files
• Auto-loading
!
• Semantic versioning
• Branches
• Tags
• Backward compatibility
• Quality control
1 - The Release Reuse Equivalence Principle
The Rule of Three
blog.codinghorror.com/rule-of-three/
1 - The Release Reuse Equivalence Principle
If you don't have the time to turn your
reusable code into a proper package...
!
Don't release it.
2- The Common Reuse Principle
Classes that are used together are packaged
together
If you use one class of a package,
you will use all its other classes too.
2- The Common Reuse Principle
Smell: Feature strata
2- The Common Reuse Principle
Example of feature strata: the Symfony
Security Component
2- The Common Reuse Principle
Smell: Classes with different
dependencies
2- The Common Reuse Principle
Example of different dependencies:
Gaufrette
2- The Common Reuse Principle
Different dependencies: Gaufrette
{
"name": "knplabs/gaufrette",
...
"suggest": {
"knplabs/knp-gaufrette-bundle": "to use with Symfony2",
"dropbox-php/dropbox-php": "to use the Dropbox adapter",
"rackspace/php-opencloud" : "to use Opencloud adapter",
"herzult/php-ssh": "to use SFtp adapter",
"phpseclib/phpseclib": "to use PhpseclibSftp adapter",
"aws/aws-sdk-php": "to use the Amazon S3 adapter",
"amazonwebservices/aws-sdk-for-php": "to use the legacy Amazon S
"doctrine/dbal": "to use the Doctrine DBAL adapter",
"microsoft/windowsazure": "to use Microsoft Azure Blob Storage a
"ext-zip": "to use the Zip adapter",
"ext-apc": "to use the APC adapter",
...
},
2 - The Common Reuse Principle
Leszek Prabucki's response
3 - The Common Closure Principle
Classes that change together are
packaged together
3 - The Common Closure Principle
Reasons for change
• The application's features change
• The business rules change
• The web framework's best practices change
• The persistence library's configuration changes
• ...
3 - The Common Closure Principle
Smell: code for multiple application layers
• Web User Interface
• Command-line interface
• Model
• Infrastructure services
B - Coupling principles
Perspective: the package in relation to other
packages
4 - The Acyclic Dependencies Principle
The dependency graph of packages must
have no cycles
4 - The Acyclic Dependencies Principle
Stability
Something is stable if it's resistant to change.
5 - The Stable Dependencies
Principle
An irresponsible package
5 - The Stable Dependencies Principle
A dependent package
5 - The Stable Dependencies Principle
An instable package: irresponsible and
dependent
5 - The Stable Dependencies Principle
A responsible package
5 - The Stable Dependencies Principle
An independent package
5 - The Stable Dependencies Principle
A stable package: responsible and
independent
5 - The Stable Dependencies Principle
Depend in the direction of stability
5 - The Stable Dependencies Principle
Counter example
6 - The Stable Abstractions Principle
What is more likely to change?
!
• Something concrete or something abstract?
• A class or an interface?
6 - The Stable Abstractions Principle
Abstractness should increase with stability
Summary
Reuse/release equivalence principle
Reuse only code that you can release as a product.
Common reuse principle
All code in a package is reused at the same time.
Common closure principle
Code in a package only changes for a few reasons.
Acyclic dependencies principle
No cycles in the dependency graph.
Stable dependencies principle
Only depend on more stable packages.
Stable abstractions principle
More stable packages are also more abstract.
Word of advice
You can't maximize them all at
the same time.
!
Keep them in mind while you are
working on a package.
Principles of Package Design
leanpub.com/principles-of-package-design/c/phpconpl
Questions?
@matthiasnoback
joind.in/16212
Thank you!
Images
• http://cleancoders.com/
• https://github.com/
• https://bitbucket.org/
• https://packagist.org/
• http://martinfowler.com/eaaCatalog/
• http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
• http://blog.8thlight.com/uncle-bob/2014/05/14/
TheLittleMocker.html

More Related Content

Viewers also liked (6)

PACKAGE DESIGN (Intro to GD, wk 12)
PACKAGE DESIGN (Intro to GD, wk 12)PACKAGE DESIGN (Intro to GD, wk 12)
PACKAGE DESIGN (Intro to GD, wk 12)
 
Research Methodology for Design
Research Methodology for DesignResearch Methodology for Design
Research Methodology for Design
 
Packaging design ppt
Packaging design pptPackaging design ppt
Packaging design ppt
 
Packaging Design Conference 12-09
Packaging Design Conference 12-09Packaging Design Conference 12-09
Packaging Design Conference 12-09
 
Packaging ppt
Packaging pptPackaging ppt
Packaging ppt
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011
 

Similar to Principles of Package Design (PHPCon Poland 2015)

Design Patterns .Net
Design Patterns .NetDesign Patterns .Net
Design Patterns .Net
Hariom Shah
 
Package Repositories: The Unsung Heroes of Configuration and Release Managem...
Package Repositories:  The Unsung Heroes of Configuration and Release Managem...Package Repositories:  The Unsung Heroes of Configuration and Release Managem...
Package Repositories: The Unsung Heroes of Configuration and Release Managem...
IBM UrbanCode Products
 

Similar to Principles of Package Design (PHPCon Poland 2015) (20)

SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Dutch Symfony Meetup - Principles of PHP Package Design
Dutch Symfony Meetup - Principles of PHP Package DesignDutch Symfony Meetup - Principles of PHP Package Design
Dutch Symfony Meetup - Principles of PHP Package Design
 
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
 
Dependency injection via annotations v1.0
Dependency injection via annotations v1.0Dependency injection via annotations v1.0
Dependency injection via annotations v1.0
 
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
 
Software design principles
Software design principlesSoftware design principles
Software design principles
 
CPAN Curation
CPAN CurationCPAN Curation
CPAN Curation
 
Solid principles
Solid principlesSolid principles
Solid principles
 
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
 
An introduction and future of Ruby coverage library
An introduction and future of Ruby coverage libraryAn introduction and future of Ruby coverage library
An introduction and future of Ruby coverage library
 
Design Patterns .Net
Design Patterns .NetDesign Patterns .Net
Design Patterns .Net
 
Seven Habits Of Highly Effective Asp Net Mvc D
Seven Habits Of Highly Effective Asp Net Mvc DSeven Habits Of Highly Effective Asp Net Mvc D
Seven Habits Of Highly Effective Asp Net Mvc D
 
Daniel leon design principles in the functional world
Daniel leon   design principles in the functional worldDaniel leon   design principles in the functional world
Daniel leon design principles in the functional world
 
Package Repositories: The Unsung Heroes of Configuration and Release Managem...
Package Repositories:  The Unsung Heroes of Configuration and Release Managem...Package Repositories:  The Unsung Heroes of Configuration and Release Managem...
Package Repositories: The Unsung Heroes of Configuration and Release Managem...
 
Introduction to Memory Contexts
Introduction to Memory ContextsIntroduction to Memory Contexts
Introduction to Memory Contexts
 
Code qualities and practices to achieve them
Code qualities and practices to achieve themCode qualities and practices to achieve them
Code qualities and practices to achieve them
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
 
2009 training - tim m - object oriented programming
2009   training - tim m - object oriented programming2009   training - tim m - object oriented programming
2009 training - tim m - object oriented programming
 
CAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and PracticesCAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and Practices
 
Principles of PHP Package Design - Laracon Europe (Amsterdam) 2014
Principles of PHP Package Design - Laracon Europe (Amsterdam) 2014Principles of PHP Package Design - Laracon Europe (Amsterdam) 2014
Principles of PHP Package Design - Laracon Europe (Amsterdam) 2014
 

More from 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
 

More from 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
 

Recently uploaded

AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 

Recently uploaded (20)

AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 

Principles of Package Design (PHPCon Poland 2015)

  • 1. Principles of Package Design How to create cohesive, stable packages Matthias Noback
  • 3. A Year With Symfony leanpub.com/a-year-with-symfony
  • 9. Principles of Package Design leanpub.com/principles-of-package-design
  • 12. A - Cohesion principles Perspective: the package in isolation
  • 13. ! 1 - The Release Reuse Equivalence Principle The granule of reuse is the granule of release
  • 14. 1 - The Release Reuse Equivalence Principle • Version control and hosting • Composer package definition • Meta-files • Auto-loading ! • Semantic versioning • Branches • Tags • Backward compatibility • Quality control
  • 15. 1 - The Release Reuse Equivalence Principle The Rule of Three blog.codinghorror.com/rule-of-three/
  • 16. 1 - The Release Reuse Equivalence Principle If you don't have the time to turn your reusable code into a proper package... ! Don't release it.
  • 17. 2- The Common Reuse Principle Classes that are used together are packaged together If you use one class of a package, you will use all its other classes too.
  • 18. 2- The Common Reuse Principle Smell: Feature strata
  • 19. 2- The Common Reuse Principle Example of feature strata: the Symfony Security Component
  • 20. 2- The Common Reuse Principle Smell: Classes with different dependencies
  • 21. 2- The Common Reuse Principle Example of different dependencies: Gaufrette
  • 22. 2- The Common Reuse Principle Different dependencies: Gaufrette { "name": "knplabs/gaufrette", ... "suggest": { "knplabs/knp-gaufrette-bundle": "to use with Symfony2", "dropbox-php/dropbox-php": "to use the Dropbox adapter", "rackspace/php-opencloud" : "to use Opencloud adapter", "herzult/php-ssh": "to use SFtp adapter", "phpseclib/phpseclib": "to use PhpseclibSftp adapter", "aws/aws-sdk-php": "to use the Amazon S3 adapter", "amazonwebservices/aws-sdk-for-php": "to use the legacy Amazon S "doctrine/dbal": "to use the Doctrine DBAL adapter", "microsoft/windowsazure": "to use Microsoft Azure Blob Storage a "ext-zip": "to use the Zip adapter", "ext-apc": "to use the APC adapter", ... },
  • 23. 2 - The Common Reuse Principle Leszek Prabucki's response
  • 24. 3 - The Common Closure Principle Classes that change together are packaged together
  • 25. 3 - The Common Closure Principle Reasons for change • The application's features change • The business rules change • The web framework's best practices change • The persistence library's configuration changes • ...
  • 26. 3 - The Common Closure Principle Smell: code for multiple application layers • Web User Interface • Command-line interface • Model • Infrastructure services
  • 27. B - Coupling principles Perspective: the package in relation to other packages
  • 28. 4 - The Acyclic Dependencies Principle The dependency graph of packages must have no cycles
  • 29. 4 - The Acyclic Dependencies Principle
  • 30. Stability Something is stable if it's resistant to change.
  • 31. 5 - The Stable Dependencies Principle An irresponsible package
  • 32. 5 - The Stable Dependencies Principle A dependent package
  • 33. 5 - The Stable Dependencies Principle An instable package: irresponsible and dependent
  • 34. 5 - The Stable Dependencies Principle A responsible package
  • 35. 5 - The Stable Dependencies Principle An independent package
  • 36. 5 - The Stable Dependencies Principle A stable package: responsible and independent
  • 37. 5 - The Stable Dependencies Principle Depend in the direction of stability
  • 38. 5 - The Stable Dependencies Principle Counter example
  • 39. 6 - The Stable Abstractions Principle What is more likely to change? ! • Something concrete or something abstract? • A class or an interface?
  • 40. 6 - The Stable Abstractions Principle Abstractness should increase with stability
  • 41. Summary Reuse/release equivalence principle Reuse only code that you can release as a product. Common reuse principle All code in a package is reused at the same time. Common closure principle Code in a package only changes for a few reasons. Acyclic dependencies principle No cycles in the dependency graph. Stable dependencies principle Only depend on more stable packages. Stable abstractions principle More stable packages are also more abstract.
  • 42. Word of advice You can't maximize them all at the same time. ! Keep them in mind while you are working on a package.
  • 43. Principles of Package Design leanpub.com/principles-of-package-design/c/phpconpl
  • 45. Images • http://cleancoders.com/ • https://github.com/ • https://bitbucket.org/ • https://packagist.org/ • http://martinfowler.com/eaaCatalog/ • http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod • http://blog.8thlight.com/uncle-bob/2014/05/14/ TheLittleMocker.html