[GR-Jug] inheritance ?
Carlus Henry
chenry at gfs.com
Mon Feb 2 15:29:28 EST 2004
Yes.....that will not work. If you think about it, the only reason why you use inheritance is to abstract relationships between objects. For example, consider the following objects:
Person
Student
Employee
It would make sense that the student and employee object would extend person. Therefore, person would have attributes like first name, last_name, middleInitial, gender....all of those attributes that describe a person.
Student and Employee objects would only have those attributes that describe them. Student would have, G.P.A., studentId, school, grade and Employee would have employeeId, salary, shift.
In the case you described, you wanted to make an attribute of Student or Employee and have that accessible to the Person object. That is something that you probably don't want to do.
Instead, I think that you are looking for an interface. An inteface would provide you with the ploymorphism that I do believe that you seek. Whenever you use an interface, the client or object that is using the interface, should not know the implementing object. Instead, he should just call methods on the interface which will then call the implementing methods on the object.
I hope this helps.....
Thanks
Carlus
>>> matt at eisgr.com 02/02/04 02:53PM >>>
You are a member of the Grand Rapids Java Users Group mailing list.
Please see the bottom of this message for information on unsubscription/customizing your preferences.
Derek Vredevoogd wrote:
>You are a member of the Grand Rapids Java Users Group mailing list.
>Please see the bottom of this message for information on unsubscription/customizing your preferences.
>Hey thanks.
>I don't know if I quite understand you're logic here.
>But, I do have an idea what you are saying.
>I can ask again at the next meeting.
>
>I was dealing a bit with polymorphism.
>I was hoping to put a private method in my
>subclass and have it still be available in
>its parent class(without declaring it in the parent) after conversion. But
>somehow I don't think that will work.
>But, then I got real confused and this
>question came to mind.
>Anyways, no worries. Not a big deal right now.
>
>------
>
>OK, here is a stumper, at least for me.
>
>Do the modifiers assigned to features in a parent class
>dictate what features will be inherited by its children?
>If so, what are the rules, and where is a good document about it?
>
>Modifiers:
>public,default,protected,default
>final,abstract,static,native,transient,
>synchronized,volatile
>
>features:
>class, method, or variable
>
>
>
There is not way to inherit up the inheritance tree. Inheritance only
flows "down" from parent to child. If you are a hack, you can cast the
parent object as its child in order to take advantage of the child's
methods, but why not just implement the method in the parent as a
"protected"? If it doesn't work for all children, reimplement over it,
or re-subclass (adopt) it under a different parent.
Make sense? To reiterate Carlus's question, what exactly are you trying
to do? Why would it make sense to NOT implement in the parent and yet
use it there?
_______________________________________________
Jug mailing list
Jug at gr-jug.org
Un/Subscribe/Customize http://gr-jug.org/mailman/listinfo/jug
More information about the Jug
mailing list