The form class seems to have no purpose. I can not do impementation getArea in the form class, since different forms calculate the area differently. I could just remove the form class and make my code simpler.
Suppose you have an image made up of several shapes - some circles, some rectangles, etc. You can save all these shapes in a List<Shape> , and then calculate the total area using:
int totalArea = 0; for (Shape shape : shapes) { totalArea += shape.getArea(); }
How would you do this if you did not have a generic class or Shape interface? Your Picture class should be aware of each individual form class, and not use the commonality between the various form classes to make the code more general.
As another example, consider threads. Imagine that we did not have an InputStream class - we only had separate subclasses. Then, each time you wrote code that was supposed to read some data, you would need to provide an overload for each individual subclass that you would like to process, although the code would be exactly the same in each method. InputStream abstracts the differences, revealing common functionality (reading, skipping, etc.). That way you can write one method that just takes an InputStream and then calls it using FileInputStream or ByteArrayInputStream , etc.) Without a method that should take care of which one it receives.
Jon skeet
source share