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

    本质上还是组合

    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();
        }
    }
  • 相关阅读:
    企业级应用和互联网应用的区别
    JAVAEE课程目标
    组队项目--投票管理系统
    关于JSON
    Ajax技术学习
    Applet的学习
    Async的相关学习
    Filter分析
    JavaEE-map
    Session
  • 原文地址:https://www.cnblogs.com/heben/p/5784316.html
Copyright © 2011-2022 走看看