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

    1.适配器

    graph LR id1(OracleUser)--继承-->id2(SqlUser) id3(MysqlUser)--继承-->id2(SqlUser) id4(Client)--调用-->id5(Adapt) id5(Adapt)--关联-->id2(SqlUser) style id1 fill:#f9f,stroke:#333,stroke-4px,fill-opacity:0.5 style id2 fill:#ccf,stroke:#f66,stroke-2px,stroke-dasharray: 10,5 style id3 fill:#f9f,stroke:#333,stroke-4px,fill-opacity:0.5 style id4 fill:#f9f,stroke:#333,stroke-4px,fill-opacity:0.5 style id5 fill:#f9f,stroke:#333,stroke-4px,fill-opacity:0.5

    客户端调用适配器中的 a 方法,a 方法将调用适配器中 SqlUser 对象的 a 方法

    client -> adapt.a => adapt.SqlUser.a
    
    public static User SelectUser(string id)
    {
        return this.IUser.SelectUser(id);
    }
    

    2.反射

    graph LR OracleUser--继承-->SqlUser MysqlUser--继承-->SqlUser Client--调用-->DataAccess DataAccess--关联-->SqlUser

    客户端调用适配器中的 a 方法,a 方法根据配置中的数据库类型字符串,
    通过反射的方式,实例化对应的数据库的类的对象并返回。

    client -> adapt.a => SqlUser。
    

    要求:数据库的类名称按一定的命名规范拼凑。

    public static IUser CreateUser()
    {
        string className = AssemblyName + ".AbstractFactory." + db + "User";
        return (IUser)Assembly.Load(AssemblyName).CreateInstance(className);
    }
    
  • 相关阅读:
    openssh升级
    Mysql基础学习_Windows版(一)
    centos7 取消Ctrl+Alt+Del重启功能
    linux shell数值比较和字符串比较
    linux 使用中括号进行条件判断
    VXLAN简介(摘抄)
    centos配置NTP服务器
    Centos配置网卡子接口
    组播___IGMP
    组播
  • 原文地址:https://www.cnblogs.com/MichaelLoveSna/p/14199065.html
Copyright © 2011-2022 走看看