Skip to content

Instantly share code, notes, and snippets.

@ssinganamalla
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssinganamalla/c39da6b987103ff35e56 to your computer and use it in GitHub Desktop.
Save ssinganamalla/c39da6b987103ff35e56 to your computer and use it in GitHub Desktop.
Single Dispatch
public class Program
{
/**
yes thats me
yes thats me
you will have to use Double Dispatch in order for u to print 2 statements
**/
public static void main(String[] args)
{
Shape shape = new Shape();
Surface surface = new Surface();
Surface etch = new EtchASketch();
shape.Draw(surface);
shape.Draw(etch);
}
}
class Surface {
}
class EtchASketch extends Surface {
}
class Shape
{
public void Draw(Surface surface)
{
System.out.println("yes thats me");
}
public void Draw(EtchASketch etchASketch)
{
System.out.println("thats you");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment