Exemplo n.º 1
0
        static void Main(string[] args)
        {
            User       user = new User();
            Department dept = new Department();

            IUserOperation userOperation = DataAccess.CreateUserOperation();
            IDeptOperation deptOperation = DataAccess.CreateDeptOperation();

            userOperation.Insert(user);
            userOperation.GetUser(3);

            deptOperation.Insert(dept);
            deptOperation.GetDepartment(4);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //使用抽象工厂模式,可以在工厂中生产多种产品
            User       user = new User();
            Department dept = new Department();
            //如果需要更换数据库,只需要修改下面这个改为其他数据库的工厂即可
            //缺点是,当增加一个表时,需要增加表类,然后增加相关表操作类,有多少数据库就要增加多少相关表操作类
            //再然后就是要修改各个数据库工厂类,在各个工厂中增加生产操作类的方法
            IDB            db            = new SqlServer();
            IUserOperation userOperation = db.CreateUserOperation();
            IDeptOperation deptOperation = db.CreateDeptOperation();

            userOperation.Insert(user);
            userOperation.GetUser(1);

            deptOperation.Insert(dept);
            deptOperation.GetDepartment(2);
            Console.ReadKey();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var user = new User();
            var dept = new Department();

            IFactory factory = new SqlServerFactory();

            IUserOperation iOper = factory.CreateUserOperation();

            iOper.Insert(user);
            iOper.GetUser(1);

            factory = new AccessFactory();

            IDepartmentOperation id = factory.CreateDepartmentOperation();

            id.Insert(dept);
            id.GetDepartment(1);

            Console.Read();
        }