public void paint(Graphics g) { for (int i
public void paint(Graphics g) { for (int i = 0; i < triangles.size(); i++) { Triangle tngl = (Triangle)triangles.elementAt(i); tngl.draw(g); } } } An example of two standard triangles is shown below in the left window, and the same code using an isoceles triangle in the right window. Templates and Callbacks Design Patterns points out that Templates can exemplify the Hollywood Principle, or Don t call us, we ll call you. The idea here is that methods in the base class seem to call methods in the derived classes. The operative word here is seem. If we consider the draw code in our base Triangle class, we see that there are 3 method calls: drawLine(g, p1, p2); Point current = draw2ndLine(g, p2, p3); closeTriangle(g, current); Now drawLine and closeTriangle are implemented in the base class. However, as we have seen, the draw2ndLine method is not implemented at all in the base class, and various derived classes can implement it differently. Since the actual methods that are being called are in the derived classes, it appears as though they are being called from the base class. If this idea make you uncomfortable, you will probably take solace in recognizing that all the method calls originate from the derived class, and that these calls move up the inheritance chain until they find the first class which implements them. If this class is the base class, fine. If not, it could be any
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services