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

  • Home
  • SEARCH
  • 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 8209531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:45:21+00:00 2026-06-07T09:45:21+00:00

Possible Duplicate: Interface vs Base class Its common to see the repository pattern implemented

  • 0

Possible Duplicate:
Interface vs Base class

Its common to see the repository pattern implemented using Interfaces

public interface IFooRepository
{
   Foo GetFoo(int ID);
}

public class SQLFooRepository : IFooRepository
{
   // Call DB and get a foo
   public Foo GetFoo(int ID) {}
}

public class TestFooRepository : IFooRepository
{
   // Get foo from in-memory store for testing
   public Foo GetFoo(int ID) {}
}

But you could equally do this using abstract classes.

public abstract class FooRepositoryBase
{
    public abstract Foo GetFoo(int ID);
}

public class SQLFooRepository : FooRepositoryBase
{
    // Call DB and get a foo
    public override Foo GetFoo(int ID); {}
}

public class TestFooRepository : FooRepositoryBase
{
    // Get foo from in-memory store for testing
    public override Foo GetFoo(int ID); {}
}

What are the specific advantages of using an Interface over an Abstract Class in a repository scenario?

(i.e. don’t just tell me that you can implement multiple interfaces, I know this already – why would you do that in a repository implementation)

Edit to clarify – pages like “MSDN – Choosing Between Classes and Interfaces” can be paraphrased as “Choose classes over interfaces unless there is a good reason not to” – what are the good reasons in the specific case of a Repository pattern

  • 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-07T09:45:22+00:00Added an answer on June 7, 2026 at 9:45 am

    The main advantage of using an interface over an abstract class in this instance is that an interface is entirely transparent: This is more of an issue where you don’t have access to the source of the class you’re inheriting from.

    However, this transparency allows you to produce unit tests of a known scope: If you test a class that accepts an interface as a parameter (using the dependency injection method), you know you’re testing the class with a known quantity; the testing implementation of the interface will only contain your testing code.

    Similarly, when testing your repository, you know you’re testing just your code in the repository. This helps to limit the number of possible variables/interactions in the test.

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

Sidebar

Related Questions

Possible Duplicate: Ternary Expression with Interfaces as a Base Class Classes: interface ISms {
Possible Duplicate: Interface vs Base class A class implementing an interface has to implement
Possible Duplicate: Why does a class implements Serializable interface? I'm using a tutorial found
Possible Duplicate: IDisposable Question I have written a class and implemented the IDisposable interface.
Possible Duplicate: Why are interfaces preferred to abstract classes? Abstract class and Interface class?
Possible Duplicate: Interface vs Base class I am not understanding the difference between an
Possible Duplicate: Why should the interface for a Java class be prefered? When should
Possible Duplicate: StructureMap singleton usage (A class implementing two interface) I'm currently designing a
Possible Duplicate: Is it safe for structs to implement interfaces? Take this code: interface
Possible Duplicate: Java Interfaces? What is the use of interface in java? Is interface

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.