• 设计模式 之 桥接模式


    本质上还是组合

    package com.test.pattern.bridge;
    
    //实现接口
    interface Implementor {
        public void operationImpl();
    }
    
    abstract class Abstraction {
        protected Implementor implementor;
        
        public Abstraction(Implementor implementor) {
            this.implementor = implementor;
        }
        
        public void operation() {
            implementor.operationImpl();
        }
    }
    
    class ConcreteImplementorA implements Implementor {
    
        public void operationImpl() {
            System.out.println("具体实现A");
        }
    }
    
    class ConcreteImplementorB implements Implementor {
    
        public void operationImpl() {
            System.out.println("具体实现B");
        }
    }
    
    class RefinedAbstraction extends Abstraction{
    
        public RefinedAbstraction(Implementor implementor) {
            super(implementor);
        }
        
        public void otherOperation() {
            System.out.println("其他操作");
        }
    }
    
    public class Test {
        public static void main(String[] args) {
            Implementor implementor = new ConcreteImplementorA();
            RefinedAbstraction abstraction = new RefinedAbstraction(implementor);
            abstraction.operation();
            abstraction.otherOperation();
        }
    }
  • 相关阅读:
    thinkphp3.2 无法加载模块
    php 使用 wangeditor3 图片上传
    nginx 配置 server
    oracle练手(一)
    Oracle练习(一)
    java运算符优先级
    数据库(mysql和oracle)
    java实现4种内部排序
    mysql-----分库分表
    NIO总结-----Buffer
  • 原文地址:https://www.cnblogs.com/heben/p/5784316.html
Copyright © 2020-2023  润新知