zoukankan      html  css  js  c++  java
  • 23种设计模式之桥接模式

    桥接模式(Bridge):将抽象部分与它的实现部分分离,使它们都可以独立地变化。

     

    package designMode.bridge;
    
    interface Implementor {
    
        void operation();
    }
    package designMode.bridge;
    
    class ConcreteImplementorA implements Implementor{
    
        @Override
        public void operation() {
            System.out.println("具体实现A的方法执行");
        }
    }
    class ConcreteImplementorB implements Implementor{
        
        @Override
        public void operation() {
            System.out.println("具体实现B的方法执行");
        }
    }
    package designMode.bridge;
    
    class Abstraction {
        
        protected Implementor implementor;
    
        public void setImplementor(Implementor implementor) {
            this.implementor = implementor;
        }
        
        public void operation(){
            implementor.operation();
        }
    }
    package designMode.bridge;
    
    class RefinedAbstraction extends Abstraction{
    
        @Override
        public void operation() {
            super.operation();
        }
    }
    package designMode.bridge;
    
    class Test {
        public static void main(String[] args) {
            Abstraction ab = new RefinedAbstraction();
            ab.setImplementor(new ConcreteImplementorA());
            ab.operation();
            ab.setImplementor(new ConcreteImplementorA());
            ab.operation();
        }
    }
  • 相关阅读:
    F. 蚂蚁装修
    D. 蚂蚁平面
    B. 蚂蚁觅食(二)
    A 蚂蚁觅食
    落谷 P1734 最大约数和
    F
    D
    Http头 Range、Content-Range(http断点续传原理)
    Http头 Range、Content-Range
    XCODE 4.5 IOS多语言设置 及NSLocalizedString和NSLocalizedStringFromTable的用法。
  • 原文地址:https://www.cnblogs.com/lxcmyf/p/7418051.html
Copyright © 2011-2022 走看看