门面模式(Facade)

门面模式(Facade)又叫外观模式

1,使用场景
为子系统中的一组接口提供一个一致的界面, Facade模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。
2,特点
1,利用高内聚来降耦合。
2,通过门面角色来控制子系统角色的方法调用,
3,UML类图

1,子系统角色:Disk,Memory,CPU
2,门面角色:Computer
3,客户端:FacadeTest
public class CPU {
    void startup(){
        System.out.println("cpu startup");
    }
    void shutdown(){
        System.out.println("cup shutdown");
    }
}
public class Disk {
    void startup(){
        System.out.println("disk startup");
    }
    void shutdown(){
        System.out.println("disk shutdown");
    }
}
public class Memory {
    void startup(){
        System.out.println("memory startup");
    }
    void shutdown(){
        System.out.println("memory shutdown");
    }
}

public class Computer {
    private CPU cpu;
    private Memory memory;
    private  Disk disk;

    public Computer(){
        this.cpu = new CPU();
        this.memory = new Memory();
        this.disk = new Disk();

    }

    void startup(){
        this.cpu.startup();
        this.disk.startup();
        this.memory.startup();
    }
    void shutdown(){
        this.memory.shutdown();
        this.disk.shutdown();
        this.cpu.shutdown();
    }
}
public class FacadeTest {
    public static void main(String[] args) {
        Computer computer = new Computer();
        computer.startup();
        computer.shutdown();
    }
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值