Essential Skills for Agile Development

Tong Ka Iok · 2004

class Shape { abstract void draw(Graphics graphics); } class Line extends Shape { Point startPoint; Point endPoint; void draw(Graphics graphics) { graphics.drawLine(getStartPoint(), getEndPoint()); } } class Rectangle extends Shape { Point lowerLeftCorner; Point upperRightCorner; void draw(Graphics graphics) { graphics.drawLine(...); graphics.drawLine(...); graphics.drawLine(...); graphics.drawLine(...); } } class Circle extends Shape { Point center; int radius; void draw(Graphics graphics) { graphics.drawCircle(getCenter(), getRadius()); } } Turning an abstract class into an interface Now, Shape is an abstract class without any executable code. It seems more appropriate to turn it into an interface: Turning an abstract class into an interface 63 Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from www.agileskills.org interface Shape { void draw(Graphics graphics); } class Line implements Shape { ... } class Rectangle implements Shape { ... } class Circle implements Shape { ... }

Read the paper · More papers on PaperTik