设计模式----代理

1、23种设计模式?
   目的:减少了代码的冗余,提高了程序的健壮性 , 提高了程序的可扩展性,程序的解耦合。
 
   积木游戏------前人总结(经验),设计的规则,设计方式方法,
        
2、代理设计模式?
   案例:dell店,老板我要一台可以玩剑灵的游戏本。
         关注:能不能玩剑灵。
   代理商代理具体电脑------在提供dell电脑基本功能的情况下,
         还完成了一些别的功能。
   servlet:
       service---get,post
       doget----
       dopost----
       String username=request.getParameter("");
 
       //业务逻辑-----代理的基本功能(dell电脑可以上网,可以玩剑灵)
 
       //请求流转。
     案例:说媒。
        找王婆给女孩--小红,找男朋友,高,帅,有钱。
 
      代理模式设计的三个角色:
      抽象角色:这类人(高富帅),dell电脑
 
      代理角色:王婆就是代理角色,合肥代理青网代理商,
 
      真是角色:小春,深圳dell场。
 
      public interface dell{
          public void shangwang();
          public void playgame();
      }
 
//合肥代理青网代理商
implements dell{
          public void shangwang(){
             //主题功能
             System.out.print("=======上网贼快=======");
             System.out.print("=======我能上网=======");
             System.out.print("=======每个月抽奖=======");
           }
          public void playgame();
     }
     合肥代理青网代理商 implements 深圳dell场{
          public void shangwang(){
 
           }
          public void playgame(){
 
          }
     }
 
 
/**
*代理角色--王婆
*/
public class WangpoAgency implements Gaofushuai{
     private gaofushai gfs;
     public WangpoAgency(){
          this.gfs = new Xiaochun();
     }
 
     public void gao(){
          gfs.gao();             //业务逻辑
 
          fumuhao();
     }
 
     public void fu(){
          gfs.fu();
     }
     public void shuai(){
          gfs.shuai();
     }
 
     public void gongzuomang(){
          System.out.println("=====心地善良=====");
     }
 
      public void fimuhao(){
          System.out.println("=====父母易相处=====");
     }
}
 
 
 
 
 
/*
*抽象角色----高富帅
*/
public interface Gaofushuai{
     public void gao();
     public void fu();
     public void shuai();
 
}
 
 
 
 
 
 
 
/*
*真实角色----
*/
 
public class Xiaochu implents GaoFushuai{
 
     public void gao(){
          System.out.println("==========我高======");
     }
 
     public void fu(){
          System.out.println("==========我富======");
          
     }
     public void shuai(){
          System.out.println("==========我帅======");
     }
     
 
}
 
 
 
 
 
public class Test{
     publc static void mian(String[ ]args){
          WangpoAgency wp = new WangAgency();
          wp.gao;
     }
}
 
 
 
 
 
 
 
 
 
 
 
 
 
原文地址:https://www.cnblogs.com/nin-w/p/5907471.html