zoukankan      html  css  js  c++  java
  • 工厂模式

    前面说了写的一个数据库管理软件
    写配置文件,包括增删改查,不同数据库都是不一样的,如果写到一个函数里,函数太长想改一个东西得找半天,
    使用工厂来解耦.参考了大话设计模式.
    private void xmlsave()
    {
    string server = this.textBoxServer.Text;
    string user = this.textBoxUid.Text;
    string password = this.textBoxPass.Text;
    string type = this.textBox_type.Text;

    Hashtable hashtable = new Hashtable();
    hashtable["server"] = server;
    hashtable["user"] = user;
    hashtable["password"] = password;
    hashtable["type"] = type;

    dbo dboone;
    dboone = dbofactory.getdbo(type);
    dboone.xmlsave(hashtable);

    xmlload();
    }
    public class dbofactory
    {
    public static dbo getdbo(string type)
    {
    //throw new System.NotImplementedException();
    if (type == "mysql")
    {
    return new dbomysql();
    }
    else if (type == "sqlserver")
    {
    return new dbosqlserver();
    }
    else
    {
    return new dbosqlserver();
    }
    }
    }
    这样代码就容易改了,学名叫可扩展性.

  • 相关阅读:
    第十四周总结
    《走出软件作坊》读后感
    航空公司信息可视化
    周总结
    REDIS实验
    第二阶段个人总结07
    第二阶段个人总结06
    第二阶段个人总结05
    第二阶段个人总结04
    第二阶段个人总结03
  • 原文地址:https://www.cnblogs.com/frog2008/p/11616481.html
Copyright © 2011-2022 走看看