In the below code, can foo‘s constructor invoke child1 or child2‘s constructor?
class child1 extends foo{
function child1(){
do_stuff();
}
}
class child2 extends foo{
function child2(){
do_stuff();
}
}
class foo{
function foo(){
// run child1, child2 etc... ? is it possible?
}
}
new foo();
Before we discuss the how to do of your question, I think we should clarify a bit on the OOP you are showing in your code here.
In your example, class foo is the base class and would have functionality, properties common to all types of foo. For example, Foo might be a tree. All trees have a trunk, roots, branches, and process sunlight into energy.
Now your child1 and child2 classes would be decendants of foo and have specific things that are in addition to or different from foo. For example, child1 might be an Oak which “is a” tree but adds the leaf property and the acorn property and the hibernate property.
Child1 and Child2 know everything there is to know about foo but foo has no idea the child1 and child2 exist.
Now if I understand what you are trying to do, you would implement that by instantiating your child1 and child2 classes and invoking whatever methods you needed on those objects from within another class or method/function.