• 桥接模式(思维导图)


    图1 桥接模式【点击查看图片】

        学习设计模式发现,很多设计模式都是很像但是侧重点不同。这些设计模式有很多实现流程相同,但是目的却不同。

    1,抽象化角色&修正抽象化角色

    package com.cnblogs.mufasa.demo1;
    
    public abstract class Abstraction {
        protected Implementor impl;
        public Abstraction(Implementor impl){
            this.impl = impl;
        }
        //示例方法
        public void operation(){
            impl.operationImpl();
        }
    }
    
    class RefinedAbstraction extends Abstraction {
        public RefinedAbstraction(Implementor impl) {
            super(impl);
        }
        //其他的操作方法
        public void otherOperation(){
    
        }
    }

    2,实现化角色&具体实现化角色

    package com.cnblogs.mufasa.demo1;
    
    public abstract class Implementor {
        /**
         * 示例方法,实现抽象部分需要的某些具体功能
         */
        public void operationImpl(){
            System.out.println("实体操作");
        }
    }
    
    class ConcreteImplementorA extends Implementor {
        @Override
        public void operationImpl() {
            System.out.println("实体A操作");
        }
    }
    
    class ConcreteImplementorB extends Implementor {
        @Override
        public void operationImpl() {
            System.out.println("实体B操作");
        }
    }

    3,客户实现类

    package com.cnblogs.mufasa.demo1;
    
    public class Client {
        public static void main(String[] args) {
            RefinedAbstraction ra=new RefinedAbstraction(new ConcreteImplementorA());
            ra.operation();
    
            RefinedAbstraction rb=new RefinedAbstraction(new ConcreteImplementorB());
            rb.operation();
        }
    }
  • 相关阅读:
    HashCode的作用
    为什么重写equals一定要重写hashcode?
    java timer 定时器原理
    java内部类作用
    jeesite添加多数据源
    Eclipse之安装Jadclipse插件直接查看class文件
    NIO和IO的主要区别
    sql 语句
    HTTP Error 500.0
    基于.NetCore3.1系列 ——认证授权方案之Swagger加锁
  • 原文地址:https://www.cnblogs.com/Mufasa/p/11390924.html
Copyright © 2020-2023  润新知