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大学"); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/cjvs9k/article/details/47056209