Posted: Sun Jul 13, 2003 12:35 am Post subject: (No subject)
hmm, I'll take a jab at trying to shed some light on inheritance...
let's take an example of the people in a school.... there will be classes for person, student, teacher and principal ... each instance of any of these classes is an object (this is the main premise of OOP)
ok so class person has data and methods (methods being functions/procedures...) that every person would have... name, age and sex for example and then methods (other than get/sets that need it - that's encapsulation... a whole other story )
now each of student, teacher and principal will inherit person as well as have some unique data and methods
so the student class might have grade, timetable and marks data
and then a method learn (probably not in a computer program... but just to help the example )
the teacher class would probably have timetable data, and possibly a set of class objects
and then a method teach
the principal class might not have any unique data, so the only data this class has would be the name, age and sex data that is inherited from person
then the principal might have a method punish or roamthehalls or what ever it is principals do
hopefully this clears it up for you if you weren't understanding the usefullness of inheritance
Sponsor Sponsor
Catalyst
Posted: Sun Jul 13, 2003 12:59 am Post subject: (No subject)
one really useful facet of inheritance is polymorphism (along with abstraction)
with polymorphism methods in a base class can be overidden in subclasses but still be accessed through the base class pointer, allowing for great flexibility
Tony
Posted: Sun Jul 13, 2003 1:03 am Post subject: (No subject)
could someone write a tutorial about all the difference inheritance types or what not... those polymorphing and other things classes can do.