1. Understanding of ideas starting with abstractfactory
Namespace Factory
{
Public abstract class abstractfactory
{
Public static abstractfactory choosefactory (string factory)
{
Return assembly. Load ("Factory"). createinstance (factory) as abstractfactory;
}
Public abstract iadminservice createadminservice ();
Public abstract iroleservice createroleservice ();
}
}
1. The customer needs to know which product (the customer processes a set of products by giving the factory. sqlfactory parameter)
Abstractfactory factory = abstractfactory. choosefactory (factory. sqlfactory) (know which product to process)
Factory. createadminservice () and factory. createroleservice () are used to instantiate a specific product (process this product) in a simple factory)
Simply put, a simple factory object is created first, and a specific entity object is created.
2. The customer needs to know what features the product has (methods provided through interfaces)
2. The following is a conceptual understanding:
1. understanding of concepts in books
1. Abstract The concept of factory design patterns: (p106)
Provides an interface for creating a series of related or mutually dependent objects without specifying their specific classes.
Series: refers to a set of products (a product family), a simple factory processing a series of products
Dependency: Products in the product family must be related. For example, either a car or a steamed bread
2. Create Factory: separates object creation and use (P105)
Understanding of separation:
1. Object creation: In a simple factory
2. object usage: when the user needs to instantiate an object, the user only needs to abstract the factory object. The abstract method returns the abstract product.
2. abstract the features of the factory model:
1. Separate object creation and use (available in both the Creation Mode)
2. Easy interaction product series (a factory creates a complete product series)
3. conducive to product consistency (only one specific factory appears in one application)
3. Abstract factories mainly deal with changes in the demand for "New Series". Its disadvantage is that it is difficult to cope with changes in the demand for "New Products ".
1. Product Family: products of the same family. For example, cups and tea cups are a product family (corresponding to a series of products). Cars and engines are also product families.
To add a product family (Oracle), you only need to add a product family physical product and the corresponding factory.
2. If the product family levels (corresponding to new products) change frequently, it is not suitable for abstract factories,
For example, a new type of product is added for automobiles and engines: tires involve changes to abstract factory classes and all their subclasses (not meeting the principle of opening and closing)
4. Abstract Factory application scenarios:
1. More than one product family
2. products of the same product family are used together.
3. The system provides a product library. All products appear on the same interface, but the client depends on the Interface rather than the implementation.
Iii. Code implementation:
I started with abstractfactory in the abstract factory class when I understood it. To write code, I 'd better follow the steps below: (the main reason is that the import references are clear and unambiguous)
Models --> iservices --> Dal --> factory --> BLL --> webui
After understanding the ideas and concepts, it is easy to write code. It should be noted that when writing the Dal, write the General sqlhelper. CS and then write other
Code download: http://www.namipan.com/downfile/Temp_AbstractFactory.rar/4811561d4355af109312f31b1b71dc645face72c91770500