|All reviews||The Clean Architecture in PHP||Latest reviews||Best sellers ranking|
The Clean Architecture in PHP
May 25, 2015
Week: 21 All time: 303
zero2hero.orgWriting code is easy, but writing the high-quality stable software that performs its purpose for a long time and is easy to maintain in time, it is hard.
That’s where architecture matters come on stage. This book "The clean architecture in PHP" is not so much about PHP code, but about the Clean Architecture.
In the first chapter of the book the author makes us realize that any piece of code you have ever created has followed some kind of architecture, even if it was just your own, since the architecture is just a structure that sets the flow of data through a system.
So technically the architectural questions start from simple things like how the files are organized or what database access abstraction is used, to more complex decisions like what are the layers your application can be divided into, otherwise a monolithic application will become a refactoring nightmare: the code becomes hard to test and hard to be changed in order to reflect the new requirements.
After that, the author suggests to use what he calls a Decoupling Toolbox: it is a combo of 5 principles how to get a quality code of well-planned architecture.
First goes first, meet the design patterns. Although there are dozens of them, you can start from learning these few: Factory, Repository, Adapter and Strategy.
These solutions help to encapsulate your application logic into well-defined areas of responsibility, and thus ease the maintenance and further changes of your code.
Next thing to apply is SOLID design principles. This set of five design rules for object oriented programming define the way in which all your classes should interact with each other and how they are organized.
To cut the long story short:
1, 2. A class and an interface should be created to solve a single problem only
3. New functionality should be added via extending a class, not modifying it
4. Interfaces should be used for families of the similar classes
5. Classes should work with abstractions, not with particular instances of other classes
And one more technique to consider is a way to get rid of hard dependencies of classes being directly instantiated in your code by using the Inversion of Control trick.
The last two techniques are: using interfaces heavily especially as the type hints, and abstracting the code with adapters to decouple from a particular framework or database layer.
In general, these design patterns and principles allow a developer to create the architecture that author calls the Clean Architecture.
What’s surprising is that the author criticises the popular MVC approach since the “M” of it which means Model is confusing. So it is better to split that into Entities and Persistence.
His point is that the Clean Architecture allows the software developers to create applications that are independent of frameworks and databases.
The author likes to play with words, so be ready to smile when you meet expressions like "the internet is literally littered with PHP" or "no names named".
“The clean architecture in PHP” is a must-read for all developers who want to reduce the technical debt to architecture of their applications and produce a good, clean and solid code.
What I like the most about this book, is that Kristopher goes further than just theoretical statements and illustrates his ideas with a case study in Clean Architecture.
The example is to build a billing system using his new approach in one hand and Zend Framework 2 in another hand, and then demonstrate how easy it is to switch the whole application to another framework Laravel. That is what the second part of the book is dedicated to.
It becomes obvious that a good architecture quickly pays back the efforts.