Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write the abstract factory pattern of java design pattern

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this article, the editor introduces in detail "how to write the abstract factory pattern of java design pattern". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to write the abstract factory pattern of java design pattern" can help you solve your doubts.

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 ("insert a user in SQL") } public UserEntity GetUser (int id) {Console.WriteLine ("get a user in SQL"); return null;}} class AccessUser: IUser {public void InsertUser (UserEntity user) {Console.WriteLine ("insert a user in Access") } public UserEntity GetUser (int id) {Console.WriteLine ("get a user in Access"); return null;}} / / change abstract factory to simple factory-> reflection public class SimpleFactory {private static string assemblyName = "abstract factory"; 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 () } after reading this, the article "how to write Abstract Factory patterns of java Design patterns" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report