Git Product home page Git Product logo

abstractfactory's Introduction

AbstractFactory-抽象工厂

将数据库从sqlserver换到mysql。

在工厂方法模式上进行进一步抽象。

如果用抽象工厂模式的话,这种切换数据库需要新增一个数据库工厂类,只需要新增一个工厂类,并将实例化工厂类的代码进行修改。

数据库工厂类和数据访问类,用接口来进行统一,面向接口编程,无论换成什么数据库,都需要实现接口。

新增一个遵循数据库工厂接口的mysqlFactory工厂类,新增一个遵循用户数据存取接口的mysqlUser控制类。 数据库修改到mysql,只需要在使用环境里修改工厂的实例化代码,原来的插入和获取用户的逻辑都不需要变化。符合开闭原则。

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        //抽象工厂模式
        User *user = [User new];
        user.name = @"丁丁";
        user.age = 28;
        
        AbstractDBFactory *afactory = [SqlServerFactory new];
//        AbstractDBFactory *afactory = [MySqlFactory new];

        AbstractUseAccess *auser = [afactory createUser];
        [auser insertUser:user];
        [auser gotUser];
    
        
    }
    return 0;
}

Cocoa框架应用

NSNumber

abstractfactory's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.