Revisit the design pattern (v)--the "abstract factory" I understand

Source: Internet
Author: User
Tags abstract oracleconnection oracle database

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:

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.