|
Posted by reandeau on 08/17/06 16:31
> I think you're confusing programming inheritance with runtime
> inheritance. Two different child objects will have two different parent
> objects.
>
> For instance - let's say you have the parent class 'Person'. As
> children of that class you have 'Employee' and 'Consultant'. Child
> classes of 'Employee' are 'HourlyEmployee' and 'SalariedEmployee'.
>
> They could have attributes such as:
>
> Person: Name, Address, etc.
> Employee: Employee ID, Department
> HourlyEmployee: Hourly rate
> SalariedEmployee: Weekly salary
> Consultant: Consulting rate
>
> Now - you do:
>
> $tom = new HourlyEmployee("Tom Jones", ...);
> $dick = new SalariedEmployee("Dick Anderson", ...);
> $harry = new Consultant("Harry Smith", ...);
>
> You would need three separate Person objects. You wouldn't want just
> one Person object - you wouldn't be able to keep all three names in it.
>
> Does this help?
>
Yea that helps tremendously. I was getting caught up with my runtime
program needing to look like my diagram. There was only one parent in
my diagram, so I was thinking "why should there be multiple parent
objects during runtime". I can see from what you stated above that
there is a need to have a parent object for each child to keep the
values stored in inherited variables associated with their prospecitve
child.
I think a big part of my issue here was that old procedural programmer
coming out in me and wanting to make the code as efficient (read: as
short) as possible. Creating all of these parent objects just didn't
seem efficient and I had gotten caught up in the idea that inheritence
must be purely for efficiency. But I can see now that, like most
things OO, inheritence is there to help make your objects as resusable
as possible- especially if done correctly.
Thanks so much for your help.
Jon
[Back to original message]
|