First
At present, the application is the yaf framework, all the controllers are 继承 self Base_controller , but due to more and more late functions (rights management, product management, log management, etc.), resulting in Base_controller no longer bloated,
Of course, it is possible to create different classes of files according to different functions, and then initialize them to Base_controller meet the requirements, but such functions and Base_controller strong coupling, so I think there is no better solution.
At the moment I'm thinking 装饰模式 , (because this is the only one, mom's egg),
Decorate with specific decorative classes (Rights Management, log management) to Base_controller make them have these functions, but because the decorative mode requires the decorator ( Base_controller ), and the specific decorators are inherited from the same class, but now Base_controller has been inherited from other classes, so Base_controller can not act as the role of the decorator,
So I worked hard to write the functional class (Rights management, product management, log management) to decorate who,
So is not my direction is wrong, decorative mode is not suitable here, or the need for other design?
Reply content:
First
At present, the application is the yaf framework, all the controllers are 继承 self Base_controller , but due to more and more late functions (rights management, product management, log management, etc.), resulting in Base_controller no longer bloated,
Of course, it is possible to create different classes of files according to different functions, and then initialize them to Base_controller meet the requirements, but such functions and Base_controller strong coupling, so I think there is no better solution.
At the moment I'm thinking 装饰模式 , (because this is the only one, mom's egg),
Decorate with specific decorative classes (Rights Management, log management) to Base_controller make them have these functions, but because the decorative mode requires the decorator ( Base_controller ), and the specific decorators are inherited from the same class, but now Base_controller has been inherited from other classes, so Base_controller can not act as the role of the decorator,
So I worked hard to write the functional class (Rights management, product management, log management) to decorate who,
So is not my direction is wrong, decorative mode is not suitable here, or the need for other design?
Using PHP's Trait
Thank you for your invitation.
Upstairs, Trait is really a solution, but the key to the problem may not be here.
Your understanding of decorative patterns is inaccurate, but not very important.
I have never encountered the problem of Basecontroller being bloated in actual development, usually this is the result of the level (or realm) of the developer, not to mention not changing the class code, even if the problem of changing the class code is not solved, but to refactor.
Often the basecontroller is bloated because many of the methods that should not be provided by the Controller are declared, and these methods may be declared in the model or referred to as helper, which is the key issue. Model is common, so its methods can be used in any controller. And if the method defined by the model is placed in the controller, and the controller is not public, the simplest solution is to put it in base, and the long-term accumulation is the result you see now.