Multidispatch pattern with OT/J [message #568322] |
Mon, 15 February 2010 14:11 |
Eugene Hutorny Messages: 110 Registered: January 2010 |
Senior Member |
|
|
The list of OT/J http://trac.objectteams.org/ot/wiki/OtPatterns does not mention multidispatch.
With smart lifting OT/J can easily provide multidispatch capabilities:
public class Shape {/*...*/}
public class Square extends Shape {/*...*/}
public class Triangle extends Shape {/*...*/}
public team class Printer {
protected class PrintableShape playedBy Shape {
protected String print() {
return "Shape";
}
}
protected class PrintableTriangle extends PrintableShape playedBy Triangle {
protected String print() {
return "Triangle";
}
}
protected class PrintableSquare extends PrintableShape playedBy Square {
protected String print() {
return "Square";
}
}
public String print(Shape as PrintableShape shape) {
return shape.print();
}
}
public class TheTest {
final Printer printer = new Printer();
Shape triangle = new Triangle();
Shape square = new Square();
public void run() {
System.out.println(printer.print(triangle)); // prints Triangle
System.out.println(printer.print(square)); // prints Square
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.03379 seconds