Any pattern for “one class per one action/page”?

Holli Evens628E

New Member
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...\[code\]class Post_Add {}class Post_Remove {}class Post_View {}\[/code\]All code, which is common for all action classes we're putting into \[code\]class Post_Parent\[/code\] and passing it's instance into action constructor.So, calling action will look like...\[code\]$parent = new Post_Parent();$action = new Post_Add($parent);$action->run();\[/code\]So, what we have?
  • Each action is in separated class, sowe can add as much private methods,vars, constants as we want.
  • All common code is separated intoparent class (\[code\]Post_Parent\[/code\]) and canbe accessed from action classes. Itis very good for organizing ACL etc.-
Is this idea worth living? Is there any similar design patterns for this?Thank you.
 
Back
Top