Hello,
MVC is a really good pattern, but sometimes it is really boring to put everything into Controller's methods. Controller is constantly growing and it takes time to get rid of thousands of code lines. Some people highly recommends to put as much as possible into Model, but I prefer to keep Model clean (I don't put controller oriented methods into Model).
The idea is to put each Controller's action into own class...
class Post_Add {}
class Post_Remove {}
class Post_View {}
All code, which is common for all action classes we're putting into class Post_Parent
and passing it's instance into action constructor.
So, calling action will look like...
$parent = new Post_Parent();
$action = new Post_Add($parent);
$action->run();
So, what we have?
- Each action is in separated class, so we can add as much private methods, vars, constants as we want.
- All common code is separated into
parent class (
Post_Parent
) and can be accessed from action classes. It is very good for organizing ACL etc.-
Is this idea worth living? Is there any similar design patterns for this?
Thank you.