|PHP Developers Network
|How to enforce *optionally used* method signatures
|Page 1 of 1|
|Author:||phpRob [ Fri May 05, 2017 2:20 pm ]|
|Post subject:||How to enforce *optionally used* method signatures|
I made this thread title as specific as I could but there are these additional constraints related to the question...
[*] I create unique/customized classes that you can think of as type "C" that extend a class "B" which in turn extends "A".
[*] It does not make sense for class "A" to use the methods which I want to enforce signatures for; it does offer much utility to "B" by "B" extending "A" ("B" must extend "A" due to good OOP design).
[*] Class "B" wants the methods to be protected and optional for all customized "C" classes (this rules out PHP Interfaces and also protected abstract functions because the methods are not to be public and are to be optionally used by "C").
[*] The methods whose signatures I wish to enforce consistently across all "C"-type classes (each having their own unique properties and thus creating the need for the existence of these classes) needs to be visible only to the class (not public).
[*] Each object of the "C" class variety must have its own unique implementation of the methods whose signatures I want enforced (this rules out the use of traits).
[*] How many methods am I talking about? just eight; but again, any class of the "C" variety can make use of 0-8 of these methods; it is consistency of their signatures I am concerned about.
If anyone has an idea how to achieve this: WOW. Because I'm thinking that I need to relax the desire to have the methods be optional and just create empty shell implementations for them in the "C"-type classes wherever they are really not needed, having made the methods abstract functions in class "B". Thankfully class "B" only needs to be extended and so I can accordingly as required make it an abstract class. But is there a better way?
|Author:||Christopher [ Sat May 06, 2017 7:21 pm ]|
|Post subject:||Re: How to enforce *optionally used* method signatures|
I am confused as to exactly what you are trying to do. Is it that you want C to inherit a different set of methods than B inherits from A. Or are you trying to have a different mix of methods available in your C class depending the situation. Either way, I think you will need to use __call() to implement this. In the first case, you can't overload from protected to private. In the second, __call() is the only way to created a dynamic interface.
|Page 1 of 1||All times are UTC - 5 hours|
|Powered by phpBB® Forum Software © phpBB Group