Seven months, two presentations and three blog posts later, I've published the first installment of my new book, Principles of PHP Package Design.

From the introduction of the book:

Naturally the biggest part of this book covers package design principles. But before we come to that, we first take a close look at what constitutes packages: classes and interfaces. The way you design them has great consequences for the characteristics of the package in which they will eventually reside. So before considering package design principles themselves, we first need to take a look at the principles that govern class design. These are the so-called SOLID principles. Each letter of this acronym stands for a different principle, each of which we will briefly (re)visit in the first part of this book.

In the second part of the book (the main part) I explain all about the six major principles of package design. The first three are about cohesion. While class cohesion is about which methods belong inside a class, package cohesion is about which classes belong inside a package. The package cohesion principles tell you which classes should be put together in a package, when to split packages, and if a combination of classes may be considered a "package" in the first place.

The second three package design principles are about coupling. Coupling is important at the class level, since most classes are pretty useless on their own. They need other classes to collaborate with. Class design principles like the dependency inversion principle help you write nicely decoupled classes. But when the dependencies of a class lie outside its own package, you need a way to determine if it's safe to couple the package to another package. The package coupling principles will help you choose the right dependencies. They will also help you recognize and prevent wrong directions in the dependency graph of your packages.

The last part of the book combines the acquired knowledge from the first two more theoretical parts. We create a couple of packages around the Gearman PHP extension, which will fix some of the shortcomings of its API and add some useful functionality on top of it. We pay great attention to which code we put in which package. And we are also very careful about the dependencies we choose for these packages.

When you buy the book now, you can already read the first part of the book (about 95 pages). Over the next months I will gradually release new chapters, covering in great detail the "Principles of Package Design", tailored to the world of PHP. The biggest part of the text has been written already, but still needs to be reviewed by myself and a couple of proof-readers.

The estimated total number of pages will be between 250 and 300 pages. I guess it will take a couple of months before I'm done, primarily depending on how family life evolves (since as you may have heard, our little girl was born just a couple of weeks ago).

Before I get back to work, let me take the time to thank some people who have helped me get here: Luis Cordova, Matthijs van Rietschoten and Mark Badolato for proof-reading the book so far, and Robert Martin for his encouragements and being a great source of inspiration.

Book PHP package design Principles of PHP Package Design release