Open main menu

CDOT Wiki β

Changes

Template Method

425 bytes added, 16:18, 19 March 2007
Pseudo Code
<pre>
abstract class AbstractRenderer{ // Define the order in which the graphical routines should be executedcoercion polymorphism void render() abstract class Add { // First draw the graphics drawGraphics public abstract double add(double d1, double d2); // Then draw the GUI on top of the graphics drawGUI(); } void drawGraphics(); void drawGUI();template
}
class Renderer AddAnyTypeNumber extends AbstractRendererAdd{ public double add(double d1, double d2) { return d1 + d2; }}class Test { public static void drawGraphicsmain(String[] args) { double d1 = 10.5, d2 = 9.5; float f1 = 11.5f, f2 = 12.5f; long l1 = 1, l2 = 2; int i1 = 3, i2 = 4; short s1 = 7, s2 = 8; byte b1 = 5, b2 = 6; AddAnyTypeNumber addNumber = new AddAnyTypeNumber(); { // Draw the graphics here System.out.println(addNumber.add(d1,d2)); } System.out.println((float)addNumber.add(f1,f2)); System.out.println((long)addNumber.add(l1,l2)); void drawGUI System.out.println((int)addNumber.add(i1,i2)); { System.out.println((short)addNumber.add(s1,s2)); // Draw the graphical user interface here System.out.println((byte)addNumber.add(b1,b2)); }
}
</pre>
1
edit