Let's talk about the simple factory model, factory method model, and abstract factory model:
- Simple Factory Pattern: the Factory class contains the necessary logic judgment, and the related class is dynamically instantiated Based on the Selection Conditions of the client. That is to say, the product creation logic is concentrated in a Factory class, the client only needs to pass different parameters to the factory. In this case, a factory creates a product and all the specific factories inherit from an abstract factory. for the client, there is no dependency with a specific product;
- Factory Method Pattern: defines the interface used to create objects in advance, so that the subclass decides to instantiate a specific class, that is, adding interfaces between the Factory and the product, the factory is no longer responsible for product creation. The interface returns specific class instances based on different conditions and is implemented by specific class instances;
- Abstract Factory Pattern: provides an interface for creating a system or mutually dependent objects without specifying a specific class. Abstract Factory, as its name says, abstracts factory interfaces, so it targets multiple equal level structures, the object creation principle is to divide the objects to be created based on objects with similar functions.
Simple factory does not belong to 23 basic design patterns. It is a special case of abstract factory patterns. The difference between Abstract Factory methods and factory methods lies in their different abstract objects: factory methods abstract products, abstract Factory abstraction targets factories. Therefore, we can think that the factory method is an extreme situation of abstract factories. The factory method mode is used to create a hierarchical structure of a product. Generally, there is only one method to create a product; abstract Factory is used to create the hierarchical structure of multiple products. Generally, there are multiple methods to create a series of products.
Mobile phone number query design
The main function of this program is to query the corresponding number locations based on the phone number segment. The data comes from the network. The data table structure is as follows:
More than 0.17 million data records
Here I use the Sqlite database to convert the database file to the Sqlite database file.
The main program interface is designed as follows:
Business Logic Analysis
The main program calls the business logic layer BLL, BLL uses the abstract factory DALFactory method, DALFactory creates the DAO instance object, and the interface layer IDAL defines the data operation interface method, the data access layer reads and writes databases through their respective public data operation class libraries to access the object class Model.
Solution file list
DBUtility is the class library for accessing public data. The three data Access layers SQLServerDAL, SqliteDAL, and OleDAL correspond to SQL Server, Sqlite, and Access databases respectively. Here I am using SqliteDAL.
Implementation
Create an object class for object Encapsulation
App. config defines the selected DAL and database connection information
Code
Public ClassList
{
Private IntId;
/// <Summary>
///No.
/// </Summary>
Public IntId
{
Get{ReturnId ;}
Set{Id=Value ;}
}
Private StringNum;
/// <Summary>
///Number segment (first 7 digits of mobile phone number)
/// </Summary>
Public StringNum
{
Get{ReturnNum ;}
Set{Num=Value ;}
}
Private StringCode;
/// <Summary>
///Zip code
/// </Summary>
Public StringCode
{
Get{ReturnCode ;}
Set{Code=Value ;}
}
Private StringCity;
/// <Summary>
///