php - Creating object from parent class and call class from child class -


i have 1 class created huge , has many methodes. want slice separate child classes.

i attempt this:


class parentclass{  }  class childclass1 extends parentclass{        public function childfunction1(){        }  }  class childclass2 extends parentclass{        public function childfunction2(){        }  }  $myobject = new parentclass(); $myobject->childfunction1(); $myobject->childfunction2(); 


not working.
it's possible?
there alternative solution?

no, not work way. you're doing instantiating empty class , trying call methods on it.

you should use composition instead. basic idea compose multiple objects main object. break off objects functionality. remember follow single responsibility principle , rest of solid.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -