zoukankan      html  css  js  c++  java
  • Matlab桥接模式

    桥接模式(Bridge)是一种结构型设计模式。它是用组合关系代替继承关系来实现,可以处理多维度变化的场景(https://blog.csdn.net/qq_31156277/article/details/80659537)。它的主要特点是把抽象(Abstraction)与行为实现(Implementation)分离开来,从而可以保持各部分的独立性以及应对他们的功能扩展。

    桥接模式的UML图如下:

    ​Implementor.m 

    classdef Implementor < handle
        methods(Abstract)
            operation(~);
        end
    end
    

    ConcreateImplementorA.m

    classdef ConcreateImplementorA < Implementor
        methods
            function operation(~)
                disp("this is concreteImplementorA's operation...");
            end
        end
    end
    

    ConcreateImplementorB.m

    classdef ConcreateImplementorB < Implementor
        methods
            function operation(~)
                disp("this is concreteImplementorA's operation...");
            end
        end
    end
    

    Abstraction.m

    classdef Abstraction < handle
        properties
            implementor
        end
        methods
            function imp = getImplementor(obj)
                imp = obj.implementor;
            end
            function setImplementor(obj,imp)
                obj.implementor = imp;
            end
            function operation(obj)
                obj.implementor.operation();
            end
        end
    end
    

    RefinedAbstraction.m

    classdef RefinedAbstraction < Abstraction
        methods
            function operation(obj)
                disp("this is RefinedAbstraction...")
                operation@Abstraction(obj);
            end
        end
    end

    测试代码:

    abstraction = RefinedAbstraction();
    abstraction.setImplementor(ConcreateImplementorA());
    abstraction.operation();
    abstraction.setImplementor(ConcreateImplementorB());
    abstraction.operation();
    

    参考资料:

    https://www.cnblogs.com/lixiuyu/p/5923160.html

    https://blog.csdn.net/qq_31156277/article/details/80659537

  • 相关阅读:
    SDOI2008 Sandy的卡片
    BZOJ2555 Substring
    CTSC2012 熟悉的文章
    递增
    丢失的牛
    【模板】点分治
    陌上花开(三维偏序)
    Holes(河鼠入洞)
    弹飞河鼠
    树状数组1
  • 原文地址:https://www.cnblogs.com/usaddew/p/11020625.html
Copyright © 2011-2022 走看看