+ All Categories
Home > Software > Principles of Package Design (PHPCon Poland 2015)

Principles of Package Design (PHPCon Poland 2015)

Date post: 16-Jan-2017
Category:
Upload: matthiasnoback
View: 750 times
Download: 7 times
Share this document with a friend
45
Principles of Package Design How to create cohesive, stable packages Matthias Noback
Transcript
Page 1: Principles of Package Design (PHPCon Poland 2015)

Principles of Package DesignHow to create cohesive, stable packages

Matthias Noback

Page 3: Principles of Package Design (PHPCon Poland 2015)

A Year With Symfony

leanpub.com/a-year-with-symfony

Page 4: Principles of Package Design (PHPCon Poland 2015)

Tight coupling

Page 5: Principles of Package Design (PHPCon Poland 2015)

What we do

Page 6: Principles of Package Design (PHPCon Poland 2015)

Packages many different kinds

Page 7: Principles of Package Design (PHPCon Poland 2015)

Class design

Page 8: Principles of Package Design (PHPCon Poland 2015)

Package design Nothing?

butunclebob.com

Page 9: Principles of Package Design (PHPCon Poland 2015)

Principles of Package Design

leanpub.com/principles-of-package-design

Page 10: Principles of Package Design (PHPCon Poland 2015)

Package design Cohesion

Page 11: Principles of Package Design (PHPCon Poland 2015)

Package design Coupling

Page 12: Principles of Package Design (PHPCon Poland 2015)

A - Cohesion principles Perspective: the package in isolation

Page 13: Principles of Package Design (PHPCon Poland 2015)

!

1 - The Release Reuse Equivalence Principle The granule of reuse is the granule of release

Page 14: Principles of Package Design (PHPCon Poland 2015)

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

Page 15: Principles of Package Design (PHPCon Poland 2015)

1 - The Release Reuse Equivalence Principle The Rule of Three

blog.codinghorror.com/rule-of-three/

Page 16: Principles of Package Design (PHPCon Poland 2015)

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.

Page 17: Principles of Package Design (PHPCon Poland 2015)

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.

Page 18: Principles of Package Design (PHPCon Poland 2015)

2- The Common Reuse Principle Smell: Feature strata

Page 19: Principles of Package Design (PHPCon Poland 2015)

2- The Common Reuse Principle Example of feature strata: the Symfony Security Component

Page 20: Principles of Package Design (PHPCon Poland 2015)

2- The Common Reuse Principle Smell: Classes with different dependencies

Page 21: Principles of Package Design (PHPCon Poland 2015)

2- The Common Reuse Principle Example of different dependencies: Gaufrette

Page 22: Principles of Package Design (PHPCon Poland 2015)

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 S3 adapters", "doctrine/dbal": "to use the Doctrine DBAL adapter", "microsoft/windowsazure": "to use Microsoft Azure Blob Storage adapter", "ext-zip": "to use the Zip adapter", "ext-apc": "to use the APC adapter", ... },

Page 23: Principles of Package Design (PHPCon Poland 2015)

2 - The Common Reuse Principle Leszek Prabucki's response

Page 24: Principles of Package Design (PHPCon Poland 2015)

3 - The Common Closure Principle Classes that change together are packaged together

Page 25: Principles of Package Design (PHPCon Poland 2015)

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 • ...

Page 26: Principles of Package Design (PHPCon Poland 2015)

3 - The Common Closure Principle Smell: code for multiple application layers

• Web User Interface • Command-line interface • Model • Infrastructure services

Page 27: Principles of Package Design (PHPCon Poland 2015)

B - Coupling principles Perspective: the package in relation to other packages

Page 28: Principles of Package Design (PHPCon Poland 2015)

4 - The Acyclic Dependencies Principle The dependency graph of packages must have no cycles

Page 29: Principles of Package Design (PHPCon Poland 2015)

4 - The Acyclic Dependencies Principle

Page 30: Principles of Package Design (PHPCon Poland 2015)

Stability

Something is stable if it's resistant to change.

Page 31: Principles of Package Design (PHPCon Poland 2015)

5 - The Stable Dependencies Principle An irresponsible package

Page 32: Principles of Package Design (PHPCon Poland 2015)

5 - The Stable Dependencies Principle A dependent package

Page 33: Principles of Package Design (PHPCon Poland 2015)

5 - The Stable Dependencies Principle An instable package: irresponsible and dependent

Page 34: Principles of Package Design (PHPCon Poland 2015)

5 - The Stable Dependencies Principle A responsible package

Page 35: Principles of Package Design (PHPCon Poland 2015)

5 - The Stable Dependencies Principle An independent package

Page 36: Principles of Package Design (PHPCon Poland 2015)

5 - The Stable Dependencies Principle A stable package: responsible and independent

Page 37: Principles of Package Design (PHPCon Poland 2015)

5 - The Stable Dependencies Principle Depend in the direction of stability

Page 38: Principles of Package Design (PHPCon Poland 2015)

5 - The Stable Dependencies Principle Counter example

Page 39: Principles of Package Design (PHPCon Poland 2015)

6 - The Stable Abstractions Principle What is more likely to change?

!

• Something concrete or something abstract?

• A class or an interface?

Page 40: Principles of Package Design (PHPCon Poland 2015)

6 - The Stable Abstractions Principle Abstractness should increase with stability

Page 41: Principles of Package Design (PHPCon Poland 2015)

SummaryReuse/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.

Page 42: Principles of Package Design (PHPCon Poland 2015)

Word of advice

You can't maximize them all at the same time.

!Keep them in mind while you are

working on a package.

Page 43: Principles of Package Design (PHPCon Poland 2015)

Principles of Package Design

leanpub.com/principles-of-package-design/c/phpconpl

Page 44: Principles of Package Design (PHPCon Poland 2015)

Questions?

@matthiasnoback

joind.in/16212

Thank you!

Page 45: Principles of Package Design (PHPCon Poland 2015)

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


Recommended