Jump to content

Overloading Classes


bsmither

Recommended Posts

There's a conversation on github that discusses a plugin's use of CubeCart's classes.

 

The conversation terminates with the opinion that the plugin should EXTEND the stock class to add functionality that the class currently does not have.

 

In reviewing the 'private'/'protected' nature of non-public object members, I am concerned that extends is not the solution the plugin can use.

 

Specifically, a private member of the parent cannot be seen by the child's methods.

 

Compare any of CubeCart's classes to the Database_Contoller class. It's evident that Database_Contoller is intended to be extended having restricted members be 'protected' instead of 'private'.

 

So what would be the solution if my plugin needs to overload a method that does not have hook in it, or not where I need one?

 

What would the ramifications be if all the classes were recoded to use 'protected' instead of 'private' members -- except those that have super-critical importance to not be messed with?

Link to comment
Share on other sites

My first foray into extending a class has come to an abrupt and early halt.

 

First and foremost, getting access to private functions will likely be necessary.

 

Then there is the problem of code using the CLASS::getInstance()->method($args) format when maybe/definitely there is the case where a class has already been destroyed during PHP shutdown.

Link to comment
Share on other sites

My experiment continues.

 

After duplicating a private function in my child class, that step of the experiment works. Unless and until private functions get changed to protected functions, duplicating some functions will probably be the way it has to be. And that will cause a more expansive maintenance plan.

 

The next step is to somehow find and use a hook before the class I am extending, itself, gets an instance.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...