static void Main(string[] args) { //抽象工厂实现方式 User userModel = new User { Name = "zhangsan" }; IUser user = null; IFactory factory = new AccessFactory(); user = factory.CreateUser(); user.AddUser(userModel); //简单工厂实现方式 DataAccess dataAccess = new DataAccess(); IDepartment department = dataAccess.CreateDepartment(); department.AddDepartment(new Department() { Name = "hahah", Remark = "测试" }); //简单工厂的switch 替换为反射 IUser Iuser2 = dataAccess.CreateUser(); Iuser2.GetSingleUser(userModel); IUser iuser = null; SqlServerUser user3 = new SqlServerUser(); iuser = (IUser)user3; Console.ReadKey(); }
static void Main(string[] args) { User user = new User(); //AbstractFactory factory = new SqlServerFactory(); IFactory factory = new AccessFactory(); IUser iu = factory.CreateUser(); iu.Insert(user); iu.GetUser(1); Console.Read(); }
public static void AbstractFactoryPattern() { User user = new User(); Department dept = new Department(); AbstractFactoryPattern.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.Read(); }
static void Main(string[] args) { User user = new User(); Department dept = new Department(); //AbstractFactory factory = new SqlServerFactory(); 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.Read(); }
static void Main(string[] args) { User user = new User(); Department dept = new Department(); // IFactory factory = new SqlServerFactory(); 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.WriteLine(ConfigurationSettings.AppSettings["DB"]); Console.ReadKey(); }