17. A - Cohesion principles
Perspective: the package in isolation
17/52
18. 1 - The Release Reuse Equivalence Principle
The granule of reuse is the granule of release
18/52
19. 1 - The Release Reuse Equivalence Principle
Version control and hosting
Composer package definition
Meta-files
Auto-loading
·
·
·
·
Semantic versioning
Quality control
·
Branches
Tags
Backward compatibility
-
-
-
·
19/52
20. 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.
20/52
21. 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.
21/52
22. 2- The Common Reuse Principle
Smell: Feature strata
22/52
23. 2- The Common Reuse Principle
Example of feature strata: the Symfony Security Component
23/52
24. 2- The Common Reuse Principle
Smell: Classes with different dependencies
24/52
25. 2- The Common Reuse Principle
Example of different dependencies: Gaufrette
25/52
26. 2- The Common Reuse Principle
Different dependencies: Gaufrette
{
"name":"knplabs/gaufrette",
...
"suggest":{
"knplabs/knp-gaufrette-bundle":"tousewithSymfony2",
"dropbox-php/dropbox-php":"tousetheDropboxadapter",
"rackspace/php-opencloud":"touseOpencloudadapter",
"herzult/php-ssh":"touseSFtpadapter",
"phpseclib/phpseclib":"tousePhpseclibSftpadapter",
"aws/aws-sdk-php":"tousetheAmazonS3adapter",
"amazonwebservices/aws-sdk-for-php":"tousethelegacyAmazonS3adapters",
"doctrine/dbal":"tousetheDoctrineDBALadapter",
"microsoft/windowsazure":"touseMicrosoftAzureBlobStorageadapter",
"ext-zip":"tousetheZipadapter",
"ext-apc":"tousetheAPCadapter",
...
},
...
} 26/52
27. 2 - The Common Reuse Principle
Leszek Prabucki's response
27/52
28. 3 - The Common Closure Principle
Classes that change together are packaged together
28/52
29. 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
...
·
·
·
·
·
29/52
30. 3 - The Common Closure Principle
Smell: code for multiple application layers
Web User Interface
Command-line interface
Model
Infrastructure services
·
·
·
·
30/52
31. B - Coupling principles
Perspective: the package in relation to other packages
31/52
32. 4 - The Acyclic Dependencies Principle
The dependency graph of packages must have no cycles
32/52
35. 5 - The Stable Dependencies Principle
An irresponsible package
35/52
36. 5 - The Stable Dependencies Principle
A dependent package
36/52
37. 5 - The Stable Dependencies Principle
An instable package: irresponsible and dependent
37/52
38. 5 - The Stable Dependencies Principle
A responsible package
38/52
39. 5 - The Stable Dependencies Principle
An independent package
39/52
40. 5 - The Stable Dependencies Principle
A stable package: responsible and independent
40/52
41. 5 - The Stable Dependencies Principle
Depend in the direction of stability
41/52
42. 5 - The Stable Dependencies Principle
Counter example
42/52
43. 6 - The Stable Abstractions Principle
What is more likely to change?
Something concrete or something abstract?
A class or an interface?
·
·
43/52
44. 6 - The Stable Abstractions Principle
Abstractness should increase with stability
44/52
45. Summary
Reuse/release equivalence principle
Common reuse principle
Common closure principle
Acyclic dependencies principle
Stable dependencies principle
Stable abstractions principle
·
Reuse only code that you can release as a product.-
·
All code in a package is reused at the same time.-
·
Code in a package only changes for a few reasons.-
·
No cycles in the dependency graph.-
·
Only depend on more stable packages.-
·
More stable packages are also more abstract.-
45/52
46. Word of advice
You can't maximize them all at the same time.
Keep them in mind while you are working on a package.
46/52
47. Principles of PHP Package Design
leanpub.com/principles-of-php-package-design
I'm impressed. â Robert C. Martin
47/52
48. Principles of PHP Package Design
Get a 10 dollar discount:
http://leanpub.com/principles-of-php-package-design/c/domcode
48/52