Introduction to OOP: Chapter 9: Mechanisms for Software Reuse [next] [previous] [audio] [real] [text]

Using Inheritance

Only need specify what is new - the addition method. Everything else is given for free.

class Set : public List { 
public: 
	void add(int);
};

void Set::add(int x) 
{
	if (! includes(x)) // only include if not already there
		List::add(x);
}
Intro OOP, Chapter 9, Slide 8