Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Subclasses
Index -> Programming, C++ -> C++ Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
PaddyLong




PostPosted: 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 Wink)

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 Razz)

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
Sponsor
sponsor
Catalyst




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
SilverSprite




PostPosted: Sun Jul 13, 2003 1:23 am   Post subject: (No subject)

yeah i'd like for a simple tutorial for polymorphism and abstraction.. inheritance is simple enough..
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 19 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: