23.07.2012 Views

Design Patterns Explained

Design Patterns Explained

Design Patterns Explained

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

158 Part III <strong>Design</strong> <strong>Patterns</strong><br />

Example 9-5 C++ Code Fragments:<br />

Rectangles and Circles without Bridge (continued)<br />

// V1Rectangle and V2Rectangle both derive from<br />

// Rectangle header files not shown<br />

void V1Rectangle::drawLine (<br />

double x1,y1, x2,y2) {<br />

DP1.draw_a_line(x1,y1,x2,y2);<br />

}<br />

void V2Rectangle::drawLine (<br />

double x1,y1, x2,y2) {<br />

DP2.drawline(x1,x2,y1,y2);<br />

}<br />

}<br />

class Circle : Shape {<br />

public:<br />

void draw() ;<br />

protected:<br />

void drawCircle(<br />

double x, y, z) ;<br />

}<br />

void Circle::draw () {<br />

drawCircle();<br />

}<br />

// V1Circle and V2Circle both derive from Circle<br />

// header files not shown<br />

void V1Circle::drawCircle (<br />

DP1.draw_a_circle(x, y, r);<br />

}<br />

void V2Circle::drawCircle (<br />

DP2.drawcircle(x, y, r);<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!