• 抽象工厂


    ############  User表 ##################
    class User(object):
        def insert(self):
            pass
        def select(self):
            pass
    
    class MysqlUser(User):
        def insert(self):
            print("MySQL: 给User表增加一条记录")
        def select(self):
            print("MySQL: 根据ID查询User表的记录")
    
    class OracleUser(User):
        def insert(self):
            print("Oracle: 给User表增加一条记录")
        def select(self):
            print("Oracle: 根据ID查询User表的记录")
    
    ############## Department表 ####################
    class Department(object):
        def insert(self):
            pass
        def select(self):
            pass
    
    class MysqlDepartment(Department):
        def insert(self):
            print("MySQL: 给Department表增加一条记录")
        def select(self):
            print("MySQL: 根据ID查询Department表的记录")
    
    class OracleDepartment(Department):
        def insert(self):
            print("Oracle: 给Department表增加一条记录")
        def select(self):
            print("Oracle: 根据ID查询Department表的记录")
    
    ########## 抽象工厂类 ################
    class Factory:
        def create_user(self):
            pass
        def create_department(self):
            pass
    
    class MysqlFactory(Factory):
        def create_user(self):
            return MysqlUser()
        def create_department(self):
            return MysqlDepartment()
    
    class OracleFactory(Factory):
        def create_user(self):
            return OracleUser()
        def create_department(self):
            return OracleDepartment()
    
    if __name__ == '__main__':
        factory = OracleFactory()  OracleFactory
        user = factory.create_user()
        user.insert()
        user.select()
        department = factory.create_department()
        department.insert()
        department.select()
    
    抽象工厂
    View Code
  • 相关阅读:
    毫秒倒计时小Demo
    css3 翻转
    canvas
    html5
    css3
    一些免费的svn空间(SVN代码托管)
    Xcode 6制作动态及静态Framework
    ios 动态执行的代码
    ios nsarray对象问题
    iOS xcode 编译选项 architecture(cup架构问题)
  • 原文地址:https://www.cnblogs.com/hanqian/p/6921688.html
Copyright © 2020-2023  润新知