• 桥接模式


    桥接(Bridge)是用于把抽象化与实现化解耦,使得二者可以独立变化

     Abstraction

    package design.pattern.bridge;
    
    public abstract class Abstraction {
        protected Implementor impl;
        public Abstraction(Implementor impl) {
            this.impl = impl;
            this.impl.setAbstraction(this);
        }
        public void operation() {
            impl.operation();
        }
    }

    Implementor

    package design.pattern.bridge;
    
    public interface Implementor {
        public void operation();
        public void setAbstraction(Abstraction abstraction);
    }

    ConcreteAbstraction

    package design.pattern.bridge;
    
    public class ConcreteAbstraction extends Abstraction {
        public ConcreteAbstraction(Implementor impl) {
            super(impl);
        }
    
        @Override
        public void operation() {
            System.out.println("ConcreteAbstraction do sth");
            impl.operation();
        }
    }

    ConcreteImplementor

    package design.pattern.bridge;
    
    public class ConcreteImplementor implements Implementor{
        private Abstraction abstraction;
    
        public void setAbstraction(Abstraction abstraction) {
            this.abstraction = abstraction;
        }
        @Override
        public void operation() {
            System.out.println("ConcreteImplementor do sth with: " + abstraction);
        }
        
    }

    Client

    package design.pattern.bridge;
    
    public class Client {
        public static void main(String[] args) {
            new ConcreteAbstraction(new ConcreteImplementor()).operation();
        }
    }
  • 相关阅读:
    cull/clip distance example
    Sutherland-Hodgeman多边形裁剪
    OpenCV 脸部跟踪(3)
    人脸识别中的Procruster analysis应用
    卡尔曼滤波的原理说明
    偏导数
    泊松分布E(X^2)
    抽奖概率
    卡尔曼滤波的原理说明
    卡尔曼滤波3
  • 原文地址:https://www.cnblogs.com/m2492565210/p/7461549.html
Copyright © 2020-2023  润新知