Best usage and examples of inheritance

Associate
Joined
18 Feb 2010
Posts
940
Hi,

I'm doing a little bit of lab work and have to set a coursework. I've been thinking of ideas for a programming task regarding inheritance. I was considering chess pieces but don't really want to do a game since some people will have the disadvantage of not knowing the rules. There is also shapes inheriting from a shape class but it's a bit too simple. I'm looking for something fun, with multiple sub classes and which isn't too easy (it's a final piece).

Any ideas? I'm just looking for good real world ideas, a little inspiration.
 
Last edited:
Associate
OP
Joined
18 Feb 2010
Posts
940
The classic one is some sort of motor vehicle I thought.

Yep, I read that in a few books too and was thinking about that one.
It needs to be a bit difficult though, perhaps:

Vehicle class extended by car, truck, motorbike, sportscar, pushbike

A race object which can take a list of vehicles and a track in the constructor and has a start() method perhaps.

A track object which is probably read from a file. Different vehicles can be better or worse at certain parts of the track, ie motorbike is better at turning, a sportscar is faster on straights.

hmmm. Still thinking.
 

AJK

AJK

Associate
Joined
8 Sep 2009
Posts
1,722
Location
UK
Can you define "a bit difficult"? What level of student are you teaching - night class, A-Level, final year University Comp Science? (I hope not the last!)

If all you're trying to teach is the concept of inheritance, this isn't particularly difficult and a simple task or two would be best. If you're setting some kind of final test for a whole programming course, then your race/track modelling idea starts to make sense.
 
Last edited:

fez

fez

Caporegime
Joined
22 Aug 2008
Posts
25,806
Location
Tunbridge Wells
The difficulty could come from anything really. As you say, you could simulate a race, you could simulate wear to the vehicles based on distance travelled. Sometimes its good to use a vague specification to see what creativity the students possess and how keen they are to take it beyond the basics.
 
Soldato
Joined
27 Mar 2003
Posts
2,710
The other classic inheritance examples are airplanes and banks/bank accounts.

Other examples could be:

People/families/groups of people
Planets, moons, stars (all things space related)
Chemistry (atoms, molecules, sub atomic particles)
Music (different genres)
cities/towns/road networks
Animal species


Just a few that came to mind.
 
Associate
OP
Joined
18 Feb 2010
Posts
940
Can you define "a bit difficult"? What level of student are you teaching - night class, A-Level, final year University Comp Science? (I hope not the last!)

If all you're trying to teach is the concept of inheritance, this isn't particularly difficult and a simple task or two would be best. If you're setting some kind of final test for a whole programming course, then your race/track modelling idea starts to make sense.

Final as in University last coursework 1st year, not final as in final year. Some interesting ideas here.
 

AJK

AJK

Associate
Joined
8 Sep 2009
Posts
1,722
Location
UK
Final as in University last coursework 1st year, not final as in final year. Some interesting ideas here.

Is the test specifically about inheritance, or all aspects of object-oriented programming? I don't remember ever having any coursework which tested only inheritance, because it's a simple concept and an example of it can be drawn out in a minute or so.

The race model you suggested earlier sounds good as a broader object-oriented programming task, but beware of making it too complicated (for example, modelling acceleration, handling, overtaking, etc.)

davetherave2 suggested bank accounts - good example with several layers, could create a basic account management page showing a few current & savings accounts with methods to display balances, perform transfers, etc?
 
Back
Top Bottom