Quantcast
Channel: PHP Website Development » MVC
Viewing all articles
Browse latest Browse all 15

How to add design patterns to CakePHP? [closed]

$
0
0

I am using the CakePHP framework to implement a Web application. I would add my application a design pattern, specifically, the Template Method pattern.
Regardless of the pattern you want to implement, where should I create interfaces (and classes) to implement a design pattern that can be used for a model?.
Where should place the files that shape a pattern (/ app / models, / app / controllers, …)?.
Design patterns that I add to my application, should be used by the models or controllers?.
Thanks for the help,
Greetings!
………………………………………

First of all, I did a lot of projects (small, medium, large) using CakePHP but never needed any extra pattern (They have already used many patterns in core). Maybe my applications were not that complex :)

In my opinion it would be better if you make plugins. You can make them component or behaviour depending upon your usage.
You can always create new folders. I think creating a new /interfaces folder would be a great idea.
No, don’t put them under controllers or models. As I mentioned above make component or behaviour.
………………………………………

I see two main issues with implementing additional design patterns in a CakePHP application:
Where to put the files to keep the conventions of CakePHP
How to implement each pattern to avoid breaking the actual MVC pattern over which CakePHP is built upon
For instance, I have had some problems in the past trying to introduce several level of inheritance between AppModel and the final models. I ended up using behaviors, components or plugins.
The CakePHP core uses several design patterns internally (factory, delegate,…). You can take a look at how are they implemented and maybe it’ll give you an idea on how to proceed with your specific issue.
To sum up: think carefully about the necessity of these design patterns. And if you definitely have to do that try to group them on an “atomic” unit, e.g. a behavior, a component,…


Viewing all articles
Browse latest Browse all 15

Latest Images

Trending Articles





Latest Images