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

    关于桥接模式大家都很熟悉,设计模式书上也介绍的非常清楚,但介绍Client调用的不多

    客户端调用有多种方式

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 using DesignPattern.Bridge;
     5 
     6 namespace DesignPattern
     7 {
     8     class Program
     9     {
    10         static void Main(string[] args)
    11         {
    12             Abstraction a = new RefinedAbstraction(new ConcreteImplementor());
    13             a.Operation();
    14             
    15         }
    16     }
    17 }
    通过构造器注入
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 using DesignPattern.Bridge;
     5 
     6 namespace DesignPattern
     7 {
     8     class Program
     9     {
    10         static void Main(string[] args)
    11         {
    12             Abstraction a = new RefinedAbstraction();
    13             a.Imp = new ConcreteImplementor();
    14             a.Operation();
    15             
    16         }
    17     }
    18 }
    Set注入

     两种方式都可以实现注入真正的实现类,但是Set方式要稍好些,以后再更换为类似Spring框架注入的时候,非常方便

  • 相关阅读:
    MongoDb
    js暴露内部方法属性等
    JS闭包
    k8s设计模式
    scrum
    死锁
    Linux下安装php 扩展fileinfo
    linux中whereis、which、find、location的区别和用法
    Linux 命令学习记录
    windows 下 redis 的安装及使用
  • 原文地址:https://www.cnblogs.com/xqlcrystal/p/Bridge-Client.html
Copyright © 2011-2022 走看看