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.

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

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

The Bridge Implemented (continued)<br />

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

drawLine(_x1,_y1,_x2,_y1);<br />

drawLine(_x2,_y1,_x2,_y2);<br />

drawLine(_x2,_y2,_x1,_y2);<br />

drawLine(_x1,_y2,_x1,_y1);<br />

}<br />

class Circle {<br />

public: Circle (<br />

Drawing *dp,<br />

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

};<br />

Circle::Circle (<br />

Drawing *dp,<br />

double x, double y,<br />

double r) : Shape(dp) {<br />

_x= x;<br />

_y= y;<br />

_r= r;<br />

}<br />

Circle::draw () {<br />

drawCircle( _x, _y, _r);<br />

}<br />

class Drawing {<br />

public: virtual void drawLine (<br />

double x1, double y1,<br />

double x2, double y2)=0;<br />

};<br />

class V1Drawing :<br />

public Drawing {<br />

public: void drawLine (<br />

double x1, double y1,<br />

double x2, double y2);<br />

void drawCircle(<br />

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

};<br />

void V1Drawing::drawLine (<br />

double x1, double y1,<br />

double x2, double y2) {<br />

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

}<br />

(continued)

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

Saved successfully!

Ooh no, something went wrong!