Forum Moderators: coopster

Message Too Old, No Replies

calling base class constructor from sub subclass

Without refering to the base class by name ie. parent::parent?

         

penders

12:16 pm on Aug 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a base class A. Class B extends A. Class C extends B.

Class B's constructor calls the constructor in the base class with the parent:: prefix.

1. How can I call the constructor in the base class from C's constructor without referring directly to the name of the base class? ie. A::__construct(). I would like to keep it more flexible/relative in a parent::parent:: or top:: kind of way?!

2. Or may be (in true OOP style) I should restructure the code so that calling the constructor in the parent::parent:: is unneccesary?

Thanks.

daveVk

11:12 pm on Aug 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Class B's constructor should call class A's constructor, so as to be self contained.

Class C's constructor should only call class B's constructor.

penders

8:08 am on Aug 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yeah I must admit #1 (calling the base class constructor from a sub subclass) did not hang together particularly cleanly in the OOP hierarchy. I've restructured it so that Class C only calls class B's constructor. Thanks.