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


            //通过工厂创建对应数据库
            IFactory factory = new AccessFactory();
            IUser    iu      = factory.CreateUser();

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

            IDepartment id = factory.CreateDepartment();

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

            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //抽象工厂模式

            User user = new User();

            IFactory factory = new SqlserverFactory();
            Iuser    ur      = factory.CreateUser();

            ur.Inser(user);

            ur.GetUser("");

            factory = new AccessFactory();

            ur = factory.CreateUser();

            ur.Inser(user);

            ur.GetUser("");


            IDepartment dt = factory.CreateDepartment();

            dt.Insert(new Department()
            {
                Name = "马化腾", ID = "1234567"
            });
            dt.getDepartment("");


            ur = DataAccess.CreateUser();
            ur.Inser(new User()
            {
                Id = "654789", Name = "李彦宏"
            });
            ur.GetUser("");
            Console.Read();
        }