Skip to content

Instantly share code, notes, and snippets.

@darrenbkl
Last active January 13, 2020 08:17
Show Gist options
  • Save darrenbkl/a435a4ea97b6f4f14e3a33fb2b453985 to your computer and use it in GitHub Desktop.
Save darrenbkl/a435a4ea97b6f4f14e3a33fb2b453985 to your computer and use it in GitHub Desktop.
public interface Explorer {
void visit(Mercury mercury);
void visit(Mars mars);
void visit(Saturn saturn);
default void visit(Planet planet) {
System.out.println("Landed on an unknown planet...");
}
}
public class LifeExplorer implements Explorer {
@Override
public void visit(Mercury mercury) {
System.out.println("Deploying tools specific to Mercury... exploring life");
}
@Override
public void visit(Mars mars) {
System.out.println("Deploying tools specific to Mars... exploring life");
}
@Override
public void visit(Saturn saturn) {
System.out.println("Deploying tools specific to Saturn... exploring life");
}
@Override
public void visit(Planet planet) {
System.out.println("Cannot explore life on an unknown planet...");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment