Nick

20%
Flag icon
Now consider the object-oriented solution in Listing 6-6. Here the area() method is polymorphic. No Geometry class is necessary. So if I add a new shape, none of the existing functions are affected, but if I add a new function all of the shapes must be changed!1 Listing 6-6 Polymorphic Shapes    public class Square implements Shape {      private Point topLeft;      private double side;      public double area() {        return side*side;      }    }    public class Rectangle implements Shape {      private Point topLeft;      private double height;      private double width;         public ...more
The Robert C. Martin Clean Code Collection (Collection) (Robert C. Martin Series)
Rate this book
Clear rating
Open Preview