Database Operations Class Library under. NET (Myado)

Source: Internet
Author: User
Tags abstract implement visual studio
ado| Data | Database Most developers have long been engaged in enterprise development work, often with the database, frequent data manipulation code is everywhere in the project, in order to remove the "repeat" in the code of the stink, some people write database operations of the class library, including many large enterprises also have their own components, But there may be different ways to implement it. I've seen it a long time ago. Sun YaminSir's article is also the application of design patterns, It was very enlightening and I wrote it. NET database Operation class Library, in fact, has long wanted to put it out to share, now a lot of database components are also very mature, and there are sqlhelper so authoritative, so I do not have to take this component and their comparison, even if to expand the expansion of ideas to everyone. First design patterns in the field of Ooa/ood is widely used, I believe that everyone in order to make their systems have high scalability and high flexibility, in their own projects are also using the design pattern. In this class library I used the "abstract factory" pattern (also the first design pattern I knew), the advantage is that the outside tell "factory" to produce what, "factory" can be honest production for external use, as for the other details of which do not need to know the outside. Now we have Project backend database to operate SQL Server, some are Oracle or some other database, there are different places in the operation (such as using different namespaces, different operating objects, etc.), we happen to be a "factory" to generate SQL for calls from outside Server or Orcale, a logical layer between the database and our application, the previous method of manipulating the database is done entirely through the component without caring for the backend database type. Here's a look at my "factory" Structure component Class graph class is Dboperator, that is, our external access to the database end use object, it is an abstract class does not use an interface. Several derived classes are odbcoperator,oledboperator,sqldboperator ... (can be redefined as needed) in order to truly implement the database operation.

Dboperatorfactory is the factory class, responsible for the "production" of a reasonable class of examples.

The Dbenum enumeration type, which lists several common data types that tell the factory what objects to produce.

The specific database operations are defined by Dboperator, such as database Open,close, and so on, and the derived class overrides the base class method to implement the operation code. The client invokes the Dboperatorfactory class's Getdboperator method directly to obtain the database operation instance to be possible (in order to use conveniently here the class also may according to the user frequently uses the database to decide, for instance I frequently use SQL Server So I have a method overload directly generates an instance of Sqldboperator. Every time you use it, don't forget the using Myado.

Download address (including source code): Http://bbs.wangxu.net/temp/myado.rar

The class diagram above is generated with Visual Studio 2005. I think it looks good, hehe. In addition, I have no problems with the. NET Framework 1.1 and the. NET Framework 2.0 (2.0 test is not sufficient). Recall that I used VB to write the ADO COM components, this is really high many ah. For your reference, welcome to discuss.



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.