DEV Community

Discussion on: The 5 SOLID principles with examples [in PHP]

Collapse
 
exadra37 profile image
Paulo Renato

I feel your pain, but I was there every month, sometimes every week, thus I end up with the Resourde Design Pattern, that @bmtich baptized by the Resource Action Pattern, and to be honest I think its a better name ;)

This pattern naturally makes easier for you to follow SOLID principles, while at same time it acts as documentation for your project, and without lies, because the folder structure is organized by all resources and actions you have in your project, instead of the traditional approach of by type of file, like Controller, Model, etc.

For a PHP example you visit this repo, and in the README of it you can see:

Anyone looking into the Resources folder can immediately see what Resources and what actions are available for each one
without the need to consult any documentation. This is the skeleton acting as documentation in our projects.
src/Resources/
├── Carts
│   ├── New
│   ├── Modify
│   ├── View
│   └── Remove
├── Categories
│   ├── New
│   ├── Modify
│   ├── View
│   └── Remove
├── Checkout
│   ├── New
│   ├── Modify
│   ├── View
│   └── Remove
├── Clients
│   ├── New
│   ├── Modify
│   ├── View
│   └── Remove
├── Products
│   ├── New
│   ├── Modify
│   ├── View
│   └── Remove
└── ...
The above skeleton by design will easily allow our code to follow the S.O.L.I.D Principles.

This approach makes it easier for a newbie or an experience developer to find the bit of code it needs to work in to fix a bug or improve a feature. To add a new feature it means usually a new resource, thus a new top level folder will need to be created.

So no more mess pilling up.

With this approach is easy to achieve PHP clases around 200-300 lines of code, and everything is isolated, thus also reduces merge conflicts in a team of developers.