Skip to content

Instantly share code, notes, and snippets.

@grimrose
Created April 16, 2012 16:02
Show Gist options
  • Save grimrose/2399667 to your computer and use it in GitHub Desktop.
Save grimrose/2399667 to your computer and use it in GitHub Desktop.
簡易メモ
public interface Finder {
List<String> find()
}
class A_Finder implements Finder {
List<String> find() {
[ "1","2" ]
}
}
class B_Finder implements Finder {
List<String> find() {
[ "3","4" ]
}
}
class Human {
void execute(String type) {
getFinder(type).find().each { println it }
}
Finder getFinder(String type) {
switch (type) {
case "A" : return new A_Finder()
case "B" : return new B_Finder()
default : null
}
}
}
Human h = new Human();
h.execute("A")
h.execute("B")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment