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.

Example 9-3 Java Code Fragments (continued)<br />

}<br />

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

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

}<br />

class Circle extends Shape {<br />

public Circle (<br />

Drawing dp,<br />

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

super( dp) ;<br />

_x= x; _y= y; _r= r ;<br />

}<br />

}<br />

public void draw () {<br />

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

}<br />

// We’ve been given the implementations for DP1 and DP2<br />

class DP1 {<br />

static public void draw_a_line (<br />

double x1,double y1,<br />

double x2,double y2) {<br />

// implementation<br />

}<br />

static public void draw_a_circle(<br />

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

// implementation<br />

}<br />

}<br />

class DP2 {<br />

static public void drawline (<br />

double x1,double x2,<br />

double y1,double y2) {<br />

// implementation<br />

}<br />

static public void drawcircle (<br />

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

// implementation<br />

}<br />

}<br />

Chapter 9 The Bridge Pattern 149

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

Saved successfully!

Ooh no, something went wrong!