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);
    }
    
  • 相关阅读:
    5. 添加后台管理页面
    4. 整合MyBatis
    3. 添加多个控制器
    2. 引入springmvc
    1. 开篇-springboot环境搭建
    去除angularjs路由的显眼的#号
    EasyUI DataGrid 分页实现示例
    等待对话框实现
    使用Struts2搭建登录注册示例
    观察者模式
  • 原文地址:https://www.cnblogs.com/MichaelLoveSna/p/14199065.html
Copyright © 2011-2022 走看看