Introduction to OOP Chapter 24: Design Patterns : next previous audio real text

Double Dispatch, continued

Each subclass of Shape must implement methods for each output device:
class Triangle : public Shape {
public:
	Triangle (Point, Point, Point);
		// ...
	virtual void displayOnPrinter (Printer);
	virtual void displayOnTerminal (Terminal);
		// ...
private:
	Point p1, p2, p3;
};

void Triangle.displayOnPrinter (Printer p) {
	// printer-specific code to 
	// display triangle
	// ...
}

void Triangle.displayOnTerminal (Terminal t) {
	// terminal-specific code to 
	// display triangle
	// ...
}
Intro OOP, Chapter 24, Slide 15