?????????????????
???????????? ???????[ 2013/8/7 11:04:16 ] ????????
//?????????????????У???????????QuackBehavior
publicclassRubberDuckextendsDuckimplementsQuackBehavior{
//?????????????
publicvoidquack(){
System.out.println("Squeak");
}
//???????????
publicvoiddisplay(){
System.out.println("Yellowhead.");
}
}
?????????????????????????????????????????????????Щ???(????fly()?????????????????????).?????????????????MallardDuck.java???????RedHeadDuck.java???Щ???????????????????á????????????????????????????????
????????γ??????????????????????????????Щ???????????????????????????????????????????????????????????????????????仯?????????????????????????????????????????????????????????
??????????????????????????????????????????????(?????????Duck)????????????????????仯????????????????????Щ??????????????????????Щ??????????????Duck???????????????????????????????????????????????????á?????ζ?????????????????????????????????????????????????????????????????С?????????μ????
????????????????б仯?????????????????????Щ??????仯???????????????????仯????????????????????????е????
??????????????????????????????????Duck????
????1)????仯???????????????
????Duck???е????fly()??quack()??????????????????????е???????????ν??仯???????
????Duck???е????swim()?????????????????????????ν??????????
??????????仯???????Duck()???а???????????????γ?????????е????????????仯??????????γ???????仯?????????????????????????????仯????????á???Щ???????Duck.java?????????????????????????????"?????"??????????????Duck.java?????????????????????????????仯?????????????????????????????У?
?????仯???????
//?仯??fly()????????γ????
publicinterfaceFlyBehavior{
voidfly();
}
//?仯??fly()????????????
publicclassFlyWithWingsimplementsFlyBehavior{
publicvoidfly(){
System.out.println("I'mflying.");
}
}
//?仯??fly()?????????????
publicclassFlyNoWayimplementsFlyBehavior{
publicvoidfly(){
System.out.println("Ican'tfly.");
}
}
//?仯??quack()????????γ????
publicinterfaceQuackBehavior{
voidquack();
}
//?仯??quack()??????????
publicclassQuackimplementsQuackBehavior{
publicvoidquack(){
System.out.println("Quack");
}
}
//?仯??quack()???????????
publicclassSqueakimplementsQuackBehavior{
publicvoidquack(){
System.out.println("Squeak.");
}
}
//?仯??quack()???????????
publicclassMuteQuackimplementsQuackBehavior{
publicvoidquack(){
System.out.println("<<Slience>>");
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11