static void Main(string[] args) { //有兩張資料表 Access跟sqlserver資料庫可以替換 User user = new User(); Department dept = new Department(); //法1 寫工廠 //IFactory factory = new AccessFactory(); IFactory factory = new SqlserverFactory(); //法2 利用DataAccess 建立實體 IUser iu = DataAccess.CreateUser(); //factory.CreateUser(); iu.Insert(user); iu.GetUser(1); IDepartment ip = DataAccess.CreateDepartment();//factory.CreateDepartment(); ip.Insert(dept); ip.GetDepartment(1); Console.ReadKey(); }
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(); }