Preliminary Exploration of design patterns-since it is inevitable at creation, it is independent!

Source: Internet
Author: User

An essential step for object-oriented design is "instantiation". If instantiation is closely integrated with specific implementations ...... There is no problem with simple creation. However, if we do not create a simple one, we need to change the specific algorithm and extend the type of the algorithm, the system needs to run after the change! Then, the problem will become complex and changeable! In several design patterns of the creation model, the implementation and instantiation of specific algorithms are separated. The factory method is a model in this regard. Other creation Design Patterns play the role of extension and assistance! The examples mentioned in the book are very interesting. You can take a good look and here let's talk about some extended knowledge. Reflection: My personal superficial understanding is that an application can dynamically obtain a type of attributes, methods, events, and other information at runtime, in this way, an object can be dynamically created in the factory! C # code: [csharp] Assembly. load ("Assembly") // Assembly. loadFile ("dynamic library for external calls") loads the Assembly, and the return type is an Assembly. The actual application is: [csharp] // introduce the reflection using System. reflection; // introduce the configuration file using System. configuration; // reflection optimization Abstract Factory // select the creation query method class DateAccess {private static readonly string AssemblyName = "shujuku" based on the Configuration file; // use the Configuration file: 1, add reference system. configuration; 2, using system. configuration // read the configuration file app. DB private static readonly st in config Ring db = ConfigurationManager. deleetask[ "DB"]; // private static readonly string db = "Sqlserver"; // create a user table using static functions: public static IUser CreateUser () {string classname = AssemblyName + ". "+ db +" User "; // use reflection to create the return (IUser) Assembly object. load (AssemblyName ). createInstance (classname);} // create the table public static IDepartment CreateDepartment () {string classname = AssemblyName + ". "+ db +" Department ";/ /Use reflection to create the return (IDepartment) Assembly object. load (AssemblyName ). createInstance (classname) ;}} in program design, the creation mode has brought us unexpected benefits, making our work easier and easier, but don't forget that one mode only solves a specific problem. Next time we will introduce more models to solve more problems!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.