none
use of DBConnection class RRS feed

  • Question

  • hello all,

    i am writng a separate class for accessing database in my application.

    for that i am extending DBConnection (present in System.Data.Common namespace) class to my class.

    but after extending it, i must have to override some extra methods & properties in my class which i don't require.

    So, Is it a proper way or or i can write my class without extending this above mentioned class.

    Also, one more query i have that is, overriding many methods & properties without their use hampers application performance?

    Please guide me over this.

    Thanks in advance.

    Friday, October 15, 2010 1:04 PM

Answers

  • The usual case for overriding DBConnection is when you are writing a database provider (also called a "driver" in some circles).  I'm guessing that you are trying to develop a Data Access Layer (DAL) instead of a database provider.  For these cases, it is more common to write your own standalone classes that contain instances (e.g., in private fields) of provider types such as SqlConnection.  In this way, you can provide methods that wrap the calls to the database provider.

    In other words, think of the OOP ideas of containment and encapsulation, not inheritance.

    > overriding many methods & properties without their use hampers application performance?

    The overhead (technically, the need to perform a "virtual call") was made inevitable when the base class designer decided to make the method overridable, not when you decided to override it.  But it is not even that much overhead to begin with.  You aren't even going to hit this overhead if the method is never called, as you seem to suggest.  Not much choice either when your only alternative is something that doesn't compile :)

    • Marked as answer by liurong luo Thursday, October 21, 2010 9:45 AM
    Friday, October 15, 2010 11:37 PM