PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Nov 22, 2017 1:29 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri May 05, 2017 2:20 pm 
Offline
Forum Newbie

Joined: Thu Feb 12, 2015 4:45 pm
Posts: 9
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?


Top
 Profile  
 
PostPosted: Sat May 06, 2017 7:21 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13447
Location: New York, NY, US
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.

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group