首页 > 代码库 > 门面模式

门面模式

门面模式【Facade Pattern 】

interface LetterProcess{
    void writeContent(String content);
    void fillEnvelope(String address);
    void LetintoEnvelope();
    void sendLetter();
}

class LetterProcessImpl implements LetterProcess{
    @Override
    public void writeContent(String content) {
        System.out.println("fill content");
    }

    @Override
    public void fillEnvelope(String address) {
        System.out.println("fill address");
    }

    @Override
    public void LetintoEnvelope() {
        System.out.println("letintoenvelope");
    }

    @Override
    public void sendLetter() {
        System.out.println("send letter into envelope");
    }
}

class ModenPost{
    private LetterProcess letterProcess = new LetterProcessImpl();
    public void sendLetter(String content,String address){
        letterProcess.writeContent(content);
        letterProcess.fillEnvelope(address);
        letterProcess.LetintoEnvelope();
        letterProcess.sendLetter();
    }
}

public class Client{
    public static void main(String[] args) {
        ModenPost modenPost = new ModenPost();
        modenPost.sendLetter("content","address");
    }
}

过年第一更

门面模式