Before you read this article, I would like to give you a reminder that my article may not be called a design pattern class article, can only be regarded as a design summary of their own projects, here, I am very welcome to discuss with me. But at the same time, I would like to say that the purpose of my blog is to hope that my experience can remind others, but if it caused a contrary effect, it is against my original intention, so I hope that everyone to my point of view, thinking, and then thinking! In addition, thanks to Jake.net, assembly head, horizontal knife smile and so on my encouragement.
1. Code Primer
Let's draw this article from a piece of code.
Believe everyone, whether it is b/s, or C/s. Are inevitably going to have to deal with the database. So this code is more common but:
static void Main(string[] args)
{
string connectionString = ".........";
SqlConnection thisConnection = new SqlConnection(connectionString);
string commandString = "select * from A";
using (thisConnection)
{
thisConnection.Open();
SqlCommand thisCommand = new SqlCommand(commandString, thisConnection);
thisCommand.ExecuteNonQuery();
}
}
This kind of code in peacetime is not controversial, the operation is also very good.
But I have encountered this situation in the company, customers say, they think that SQL Server is not good, what is not meet what needs, although he said is a fallacy, but we also have to meet the needs of customers.
Then go to the Oracle database for their request. But found that the workload is very very large. So the list was lost.
Where did the mistake come from?
2. How to modify?
string connectionString = ".............";
OracleConnection thisConnection = new OracleConnection(connectionString);
string commandString = "select * from A";
using (thisConnection)
{
thisConnection.Open();
OracleCommand thisCommand = new OracleCommand(commandString, OracleConn);
thisCommand.ExecuteNoQuery();
}
Everywhere, we need to change the code to look like this, I do not know, in a program, involved in the operation of the database code is ubiquitous. Such a large workload, it is not a short period of time can be completed. More importantly, it is possible to leave an operation undone by omission ...
3. Extraction of abstract Factory
I have never understood the meaning of this name, why is the abstract factory??
We are not going to discuss the question. into the formal topic, let's see what is the abstract factory, what is his purpose?
Provides an interface to create a series of related or interdependent objects without specifying their specific classes.
Next, let's take a look at his UML diagram: