Java???????Decorator????
???????????? ???????[ 2015/2/27 13:55:31 ] ????????Java ??????? ???
????Decorator?????????"???"??????÷????"????"???????????(decorator)????????????????????????????????decoratee?????????????Decorator???????????
????Decorator???壺????????????????Щ???????????????????????Decorator??????????????????????????????????
??????????Decorator
?????????????????ü?????????????????????Щ????????????????????????????????????????????????????????ü??????????????????????????Щ??????????Щ???????????????????????
???????Decorator???????????Щ?????????????????????????????????Decorator????"???弴??"?????????????????????????????????
???????????????
??????Adapter?е??????????Adapter??????????????? ??????Adapter???????????????????????Decorator???У??????????????????Щ??????????磬??? ???????????????????????????????????
????????????????????
????public interface Work{
????public void insert();
????}
???????Work???????????????????????????????????????Decorator??????ν???????????????????
????public class SquarePeg implements Work{
????public void insert(){
????System.out.println("?????????");
????}
????}
????????????????????????????????????????????????壬??Щ????????????????????????????????????磬????????????????????(??????)??
??????????????Decorator???????????SquarePeg??decoratee(?????????)???????????decoratee???Щ"????"????Щ????????Щ?????????
public class Decorator implements Work{
private Work work;
//?????????????????????List??
private ArrayList others = new ArrayList();
//???????????????new?????????Work????;
public Decorator(Work work){
this.work=work;
others.add("???");
others.add("?????");
}
public void insert(){
newMethod();
}
//???·????У???????insert???????????????????????????????????????
public void newMethod(){
otherMethod();
work.insert();
}
public void otherMethod(){
ListIterator listIterator = others.listIterator();
while (listIterator.hasNext()){
System.out.println(((String)(listIterator.next())) + " ???????");
}
}
}
???????????У?????????????嶼????????insert??棬????????????????????????????????
??????
???·???
??????????????????
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