Skip to content

Instantly share code, notes, and snippets.

@kyonmm
Created August 11, 2014 08:48
Show Gist options
  • Save kyonmm/2da2eaa796c03b16c277 to your computer and use it in GitHub Desktop.
Save kyonmm/2da2eaa796c03b16c277 to your computer and use it in GitHub Desktop.
DCIかどうか知らんが、おれが書きたいのはこういうのをもうちょっときれいに書くことだ。
import groovy.transform.TupleConstructor
Object.metaClass.addRole = {role ->
delegate.metaClass.mixin role
}
@TupleConstructor
class InFrontOfWoman {
def he
InFrontOfWoman(コミュ障 people){
people.addRole(Hangdog)
this.he = people
}
InFrontOfWoman(リア充 people){
people.addRole(Confident)
this.he = people
}
}
class InFrontOfFriends{
def he
InFrontOfFriends(コミュ障 people){
people.addRole(Confident)
this.he = people
}
InFrontOfFriends(リア充 people){
people.addRole(Confident)
this.he = people
}
}
class Confident{
String speak(){
"$name です!よろしくねー。"
}
}
class Hangdog{
String speak(){
"えっと。。。あの。。。"
}
String chuckIt(){
""
}
}
class People{
def name
}
class コミュ障 extends People{
}
class リア充 extends People{
}
def yamada = new リア充(name:"山田太郎");
assert new InFrontOfWoman(yamada).he.speak() == "山田太郎 です!よろしくねー。"
assert new InFrontOfFriends(yamada).he.speak() == "山田太郎 です!よろしくねー。"
def sato = new コミュ障(name:"佐藤次郎");
assert new InFrontOfWoman(sato).he.speak() == "えっと。。。あの。。。"
assert new InFrontOfFriends(sato).he.speak() == "佐藤次郎 です!よろしくねー。"
@myun2
Copy link

myun2 commented Aug 11, 2014

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment