zoukankan      html  css  js  c++  java
  • 设计模式——Facade模式,门面模式


    public interface BasFunc {
         public void startup(String message);
         public void shutdown(String message);
    }


    public class BasFunImp implements BasFunc{
         private String startInfo;
         private String shutdownInfo;
         @Override
         public void startup(String message) {
             // TODO Auto-generated method stub
             startInfo = message;
             System.out.println(startInfo);
         }

        @Override
         public void shutdown(String message) {
             // TODO Auto-generated method stub
             shutdownInfo = message;
             System.out.println(shutdownInfo);
         }
        
    }


    public class CPU implements BasFunc{
         //根据业务需要进行添加是否更加源或者细粒度的动作实现
         private BasFunc core;
         public CPU() {
             this.core = new BasFunImp();
         }
         @Override
         public void startup(String message) {
             // TODO Auto-generated method stub
             core.startup(message);
         }

        @Override
         public void shutdown(String message) {
             // TODO Auto-generated method stub
             core.shutdown(message);
         }
    }

    //


    public class Disk implements BasFunc{
         //根据业务需要进行添加是否更加源或者细粒度的动作实现
         private BasFunc core;
         public Disk() {
             this.core = new BasFunImp();
         }
         @Override
         public void startup(String message) {
             // TODO Auto-generated method stub
             core.startup(message);
         }

        @Override
         public void shutdown(String message) {
             // TODO Auto-generated method stub
             core.shutdown(message);
         }
    }

    //

    public class Memory implements BasFunc{
         //根据业务需要进行添加是否更加源或者细粒度的动作实现
         private BasFunc core;
         public Memory() {
             this.core = new BasFunImp();
         }
         @Override
         public void startup(String message) {
             // TODO Auto-generated method stub
             core.startup(message);
         }

        @Override
         public void shutdown(String message) {
             // TODO Auto-generated method stub
             core.shutdown(message);
         }
    }


    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();
         }
        
         public Computer(CPU cpu, Memory memory, Disk disk) {
             super();
             this.cpu = cpu;
             this.memory = memory;
             this.disk = disk;
         }
         public void startUp() {
             cpu.startup("cpu start up");
             memory.startup("memory start up");
             disk.startup("disk start up");
         }
        
         public void shutdown() {
             cpu.startup("cpu shut down");
             memory.startup("memory shut down");
             disk.startup("disk shut down");
         }
        
    }

    //

    public class Demo {
         public static void main(String[] args) {
             Computer computer = new Computer();
             computer.startUp();
             computer.shutdown();
         }
    }

  • 相关阅读:
    Access中出现改变字段“自己主动编号”类型,不能再改回来!(已解决)
    移动闭塞
    信号系统基本设备介绍——应答器
    行车闭塞
    计轴
    联锁
    SqlServer 查看缓存 并合理设置最大内存
    SQL Server中bcp命令的用法以及数据批量导入导出
    5 个免费的受欢迎的 SQLite 管理工具
    Qt之操作数据库(SQLite)
  • 原文地址:https://www.cnblogs.com/macro-renzhansheng/p/12568964.html
Copyright © 2011-2022 走看看