java设计模式的抽象工厂模式怎么写
发表于:2025-11-16 作者:千家信息网编辑
千家信息网最后更新 2025年11月16日,本文小编为大家详细介绍"java设计模式的抽象工厂模式怎么写",内容详细,步骤清晰,细节处理妥当,希望这篇"java设计模式的抽象工厂模式怎么写"文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一
千家信息网最后更新 2025年11月16日java设计模式的抽象工厂模式怎么写
本文小编为大家详细介绍"java设计模式的抽象工厂模式怎么写",内容详细,步骤清晰,细节处理妥当,希望这篇"java设计模式的抽象工厂模式怎么写"文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
public class UserEntity { public int ID { get; set; } public string Name { get; set; } }public interface IUser { void InsertUser(UserEntity user); UserEntity GetUser(int id); }class SqlUser: IUser { public void InsertUser(UserEntity user) { Console.WriteLine("在SQL中插入一个用户"); } public UserEntity GetUser(int id) { Console.WriteLine("在SQL中获取一个用户"); return null; } } class AccessUser : IUser { public void InsertUser(UserEntity user) { Console.WriteLine("在Access中插入一个用户"); } public UserEntity GetUser(int id) { Console.WriteLine("在Access中获取一个用户"); return null; } } //抽象工厂改简单工厂->反射 public class SimpleFactory { private static string assemblyName = "抽象工厂"; private static string db = ConfigurationSettings.AppSettings["DB"]; public static IUser CreateUser() { //switch (db) //{ // case "sql":return new SqlUser(); // case "access": return new AccessUser(); //} //return null; string className = assemblyName + "." + db + "User"; IUser iuser = (IUser)Assembly.Load(assemblyName).CreateInstance(className); return iuser; } public static IDepartment CreateIDepartment() { string className = assemblyName + "." + db + "Department"; IDepartment department = (IDepartment)Assembly.Load(assemblyName).CreateInstance(className); return department; } } static void Main(string[] args) { //UserEntity user = new UserEntity(); //IFactory factory = new AccessFactory(); //IUser su = factory.CreateUser(); //su.InsertUser(user); //su.GetUser(1); //DepartmentEntity department = new DepartmentEntity(); //IDepartment de = factory.CreateDepartment(); //de.InsertDepartment(department); //de.GetDepartment(1); //Console.ReadLine(); UserEntity user = new UserEntity(); DepartmentEntity department = new DepartmentEntity(); IUser su = SimpleFactory.CreateUser(); su.InsertUser(user); su.GetUser(1); IDepartment dep = SimpleFactory.CreateIDepartment(); dep.InsertDepartment(department); dep.GetDepartment(1); Console.ReadLine(); }读到这里,这篇"java设计模式的抽象工厂模式怎么写"文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注行业资讯频道。
工厂
模式
用户
设计模式
设计
文章
内容
妥当
思路
新知
更多
步骤
知识
知识点
篇文章
细节
行业
资讯
资讯频道
跟着
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
项目软件开发过程中的测试阶段
航天网络安全教育知识竞赛
平凉市天气预报软件开发
怎么看到我的世界服务器地址
软件开发教师
网络安全政策专家
php软件开发工作描述
在线翻译app软件开发
沈阳网络安全学校排名
网络安全用qq或微信举例
基岩版局域网服务器
金铲铲服务器ios安卓互通吗
icp网络安全工作落实情况
什么是erp服务器
哈尔滨 网络安全公司
三级数据库技术 高教版
我的世界国际版生存服务器主播
杭州万户网络技术有限公司
三级数据库技术破解版激活码
wgs数据库
河南同城生鲜配送软件开发
宁波养老这块软件开发公司排名
服务器主机名在哪看
国产网络服务器机柜哪家好
武汉互联网科技有限公司
生死狙击服务器爆满无法登录
688030网络安全
数据库创建角色报错
梦幻西游蓬莱岛服务器
网络安全服务机构备案