Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Objectteams » Multidispatch pattern with OT/J
Multidispatch pattern with OT/J [message #568322] Mon, 15 February 2010 14:11
Eugene Hutorny is currently offline Eugene HutornyFriend
Messages: 109
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
}
}
Previous Topic:OTDT 1.4.0M3 released
Next Topic:A question on design motivation for callout syntax
Goto Forum:
  


Current Time: Wed Nov 26 03:19:45 GMT 2014

Powered by FUDForum. Page generated in 0.02451 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software