外观模式---寄信

Iletterprocess.java

package PostCard;

public interface Iletterprocess {
    public  void writecontext(String context);
    public  void fillenvelope(String address);
    public  void letterintoenvelope();
    public  void sendletter();
  
}

letterprocess.java

package PostCard;

public class letterprocess implements Iletterprocess {

	@Override
	public void writecontext(String context) {
		// TODO Auto-generated method stub
		 System.err.println("写信的内容"+context);
	}

	@Override
	public void fillenvelope(String address) {
		// TODO Auto-generated method stub
		System.err.println("填写收信人地址"+address);
	}

	@Override
	public void letterintoenvelope() {
		// TODO Auto-generated method stub
		System.out.println("把信放到信封中");
	}

	@Override
	public void sendletter() {
		// TODO Auto-generated method stub
		System.out.println("邮递信件");
	}

}

police.java

package PostCard;

public class police {
	 public Boolean checkletter(String s)
     {
         if (s != null)
        	 return true;
         else 
        	 return false;
     }
 }

context.java

package PostCard;

public class context {
	private Iletterprocess i = new letterprocess();
    public void complexmethod(String con,String address)
    {
        i.writecontext(con);
        i.fillenvelope(address);
        i.letterintoenvelope();
        i.sendletter();
    }
}

facade.java

package PostCard;

public class facade {
	 //private context c=new context();
     private police p = new police();
     
     //只写了寄信方法
     public void sendletter(String con, String address)
     {
         if (p.checkletter(con))
         {
             
        	 System.out.println("审查通过,该邮件可以邮寄");        
         }
         else {
        	 System.out.println("此邮件为空邮件,无法邮寄");
         }
        	 
        	 
      }
     /*可以补充更多方法*/
}

Client.java

package PostCard;

public class Client {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 String context = "hello";
         String address = "[email protected]";
          facade f=new facade();         
        f.sendletter(context,address);
       
	}

}

运行截图:

外观模式---寄信_第1张图片

你可能感兴趣的:(设计模式)