23.07.2012 Views

Design Patterns Explained

Design Patterns Explained

Design Patterns Explained

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

The Bridge Implemented (continued)<br />

void V1Drawing::drawCircle (<br />

double x1, double y, double r) {<br />

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

}<br />

class V2Drawing : public<br />

Drawing {<br />

public:<br />

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 V2Drawing::drawLine (<br />

double x1, double y1,<br />

double x2, double y2) {<br />

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

}<br />

void V2Drawing::drawCircle (<br />

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

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

}<br />

// We have been given the implementations for<br />

// DP1 and DP2<br />

class DP1 {<br />

public:<br />

static void draw_a_line (<br />

double x1, double y1,<br />

double x2, double y2);<br />

static void draw_a_circle (<br />

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

};<br />

class DP2 {<br />

public:<br />

static void drawline (<br />

double x1, double x2,<br />

double y1, double y2);<br />

static void drawcircle (<br />

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

};<br />

Chapter 9 The Bridge Pattern 161

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

Saved successfully!

Ooh no, something went wrong!