Facade--门面模式

interface LetterProcess {
	public void writeContext(String context);

	public void fillEnvelope(String address);

	public void letterIntoEnvelope();

	public void sendLetter();
}

class PersonWriteLetter implements LetterProcess {

	@Override
	public void writeContext(String context) {
		// TODO Auto-generated method stub
		System.out.println("write the context:" + context);
	}

	@Override
	public void fillEnvelope(String address) {
		// TODO Auto-generated method stub
		System.out.println("fill Envelope with address:" + address);
	}

	@Override
	public void letterIntoEnvelope() {
		// TODO Auto-generated method stub
		System.out.println("put letter into Envelope");
	}

	@Override
	public void sendLetter() {
		// TODO Auto-generated method stub
		System.out.println("send letter");
	}

}

public class Facade {

	LetterProcess letterProcess = new PersonWriteLetter();
	
	Police police = new Police();

	public void sendLetter(String context, String address) {

		letterProcess.writeContext(context);

		letterProcess.fillEnvelope(address);

		letterProcess.letterIntoEnvelope();
		
		//任何对LetterPress操作的过程可以放在门面中。如,警察检查信件
		police.checkLetter(letterProcess);
		
		letterProcess.sendLetter();
	};
}

class Police{
	void checkLetter(LetterProcess letterProcess){
		
	}
}



/**
		 * 4.门面模式Facade
		 */
		
		System.out.println("***********4.门面模式***********");
		Facade facade = new Facade();
		facade.sendLetter("I Love u", "No.5 Street");

你可能感兴趣的:(java)