Principles of PHP Package Design

22 readers

100% Happiness guarantee Learn more

Suggested: $29.00+

Ways to buy

  • Free sample download
  • 22 readers
  • 95 pages
  • 30% complete
  • Book language: English
  • Updated

About the Book

PHP developers have all the powerful tools they need to create reusable packages of the code they write. Things like GitHub, Composer and Packagist, and an idealistic community, wanting to share code, make it very easy to bundle code and release it to the world. The tools themselves are documented very well. But it's still up to developers to decide what to put in each package, when to split the package, and on what other packages to depend. Making these choices is not easy without some guidelines or principles. This book provides exactly those: principles of PHP package design. These will help you create highly reusable and therefore highly esteemed packages.

About the Author

The Leanpub Unconditional, No Risk, 100% Happiness Guarantee

♥♥♥♥♥

Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks. We process the refunds manually, so they may take a few days to show up. See full terms.

If you buy a Leanpub book you get all the updates to the book for free! All books are available in PDF, EPUB (for iPad) and MOBI (for Kindle). There is no DRM. There is no risk, just guaranteed happiness or your money back.

Other books by this author

Table of Contents

  • Introduction
    • The situation
    • Overview of the contents
    • The “dark” side of PHP
      • About the nature of PHP and its misuse in package design
      • Dynamic typing
      • No compiler errors
      • Package maintainers misuse late symbol validation
      • Package design principles
  • Class design
    • Introduction
      • SOLID principles
      • Prepare for change
      • Why is it bad?
    • The Single responsibility principle
      • A class with too many responsibilities
      • Responsibilities are reasons to change
      • Refactoring: using collaborator classes
      • Advantages of having a single responsibility
      • A small peek ahead: common closure
    • The Open/closed principle
      • A class that is closed for extension
      • Refactoring: abstract factory
      • Refactoring: making the abstract factory open for extension
      • Refactoring: polymorphism
      • Conclusion
        • Packages need classes that are open for extension
    • The Liskov substitution principle
      • Violation: a subclass does not have an implementation for all methods
      • Violation: different substitutes return things of different types
      • Violation: a method in a subclass has stricter rules for input than its parent method
      • Violation: secretly programming against an implementation
      • Conclusion
    • The Interface segregation principle
      • Violation: leaky abstractions
        • Refactoring: create separate interfaces and use multiple inheritance
      • Violation: multiple use cases
        • Refactoring: separate interfaces and multiple inheritance
      • Violation: no interface, just a class
        • Refactoring: add header and role interfaces
    • The Dependency inversion principle
      • Example of dependency inversion: the FizzBuzz generator
      • Violation: a high-level class depends upon a low-level class
        • Refactoring: abstractions and concretions both depend on abstractions
      • Violation: a class depends upon a class from another package
        • Solution: add an abstraction and move the dependency using composition
      • Conclusion
        • Peeking ahead: abstract dependencies
  • Package design
    • Principles of cohesion
        • Becoming a programmer
        • The hardest part
      • Cohesion
        • Class design principles benefit cohesion
        • Package design principles, part I: Cohesion
    • To be continued…
  • Appendices
    • Appendix I: The full Page class

Last updated

This Book is for Sale Through Leanpub

Authors and publishers use Leanpub to publish amazing in-progress and completed books like this one.

Leanpub_logo_medium

Read

Leanpub has a wide selection of in-progress and completed books available to browse, purchase, and enjoy.

Browse the Bookstore

Write

Leanpub is free for authors and publishers to use. We pay authors or publishers 90% royalties minus 50 cents per sale.

Write a Book