Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:35:29+00:00 2026-06-02T18:35:29+00:00

I am about to build a data access layer the good old ado.net way.

  • 0

I am about to build a data access layer the good old ado.net way. Traditionally I would have built the dal according to a simple repository pattern. But this time I wanna give the Abstract Factory pattern a try because I have read about this pattern in an article lately.

So here I am try to code a dal with the abstract factory pattern. First of let me explain what I got so far. What I wanna know afterwards is whether my approach is the correct way of implementing this pattern and what the advantages are towards the repository approach.

So I wrote the following classes:

public abstract class Db
{
     //this is class will contain methods like:
     //public abstract IDbConnection CreateConnectionInstance();
}

public class SqlDb : Db
{
     //this is class will contain methods like:
     //public override IDbConnection CreateConnectionInstance()
     //{
     //      ... return new SqlConnection();
     //}
}

public class OracleDb : Db
{

}

public class MockupDb : Db
{

}

//this class generates the fitting provider but does not have a base (is this correct?)
public static class DbFactory
{
    public static Db CreateInstance(DbProviderType dbProviderType)
    {
        Db db = null;
        switch (dbProviderType)
        {
            case DbProviderType.Oracle:
                db = new OracleDb();
                break;
            case DbProviderType.Sql:
                db = new SqlDb();
                break;
            case DbProviderType.Mockup:
                db = new MockupDb();
                break;
            default:
                break;
        }
        return db;
    }
}

So my questions in short:
1) Is this a correct implementation of the abstract factory pattern?
2) What can be done better?
3) What is the advantage towards different repository classes which inherit from a base class?

Thx a lot guys.

If you need more information on my code please tell me. But there is no more at this point of time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:35:31+00:00Added an answer on June 2, 2026 at 6:35 pm

    Abstract db provider factory already exist in .Net. Its called DbProviderFactory. You can create different concrete factories via

    var factory = DbProviderFactories.GetFactory("System.Data.OracleClient");
    DbConnection connection = factory.CreateConnection();
    

    Why not to use what is already in box?

    Here you can read more about DbProviderFactories and how to add custom factory implementations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just thinking about the best way to build an Order form that would (from
I have a data access layer represented by an Eclipse project. I use Hibernate
I have a project with a formidable data access layer using LinqtoSQL for just
I am trying to re-design a data access layer that was originally built using
At my company we're about to build a new site using ASP.NET MVC. My
I have a quick question about altering the build path as the code is
i have a question about the properties of build action of files in the
I've been working on an application that has no discernable data access layer, so
I'd like ask a question about building applications in .NET that use data from
I have an ASP.NET MVC3 web application with UI, Business (entities), and Data (DbContext)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.