标签:his ice nts this 封装 str pos pattern 对象
public interface ILetterProcess { public void writerContext(String context); public void fillEnvelope(String address); public void letterIntoEnvelope(); public void sendLetter(); }
public class LetterProcess implements ILetterProcess { public void fillEnvelope(String address) { System.out.println("填写信的地址:"+address); } public void letterIntoEnvelope() { System.out.println("把信放进信封"); } public void sendLetter() { System.out.println("邮递信件"); } public void writerContext(String context) { System.out.println("写信内容:"+context); } }
public class ModenPostOffice { private ILetterProcess letterProcess=new LetterProcess(); public void sendLetter(String context,String address){ this.letterProcess.writerContext(context); this.letterProcess.fillEnvelope(address); this.letterProcess.letterIntoEnvelope(); this.letterProcess.sendLetter(); } }
public class Client { public static void main(String[] args) { ModenPostOffice postOffice=new ModenPostOffice(); postOffice.sendLetter("你被录取了", "XX大学"); } }
标签:his ice nts this 封装 str pos pattern 对象
原文地址:http://www.cnblogs.com/yutingliuyl/p/6852191.html