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 1105077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:34:30+00:00 2026-05-17T01:34:30+00:00

could some body explain me abstraction and interface in asp.net, C# by taking an

  • 0

could some body explain me abstraction and interface in asp.net, C# by taking an apprpriate example…pleasse
i am not understanding it for long

  • 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-05-17T01:34:30+00:00Added an answer on May 17, 2026 at 1:34 am

    I often find the following sample quite illuminating when it comes to explaining this:

    Disclaimer: the code examples are written directly into the text, and may contain errors that I have overseen. Please let me know if you find such errors.

    Let’s say you have a database with a Customer table, and in your code you have a customer class:

    class Customer
    {
       public int Id { get; set; }
       public string Name { get; set; }
    }
    

    In order to provide a mechanism to get customer data from the database, you need to write some class doing that. This can be placed in something called a repository. Now, we don’t want our code to rely too much on what exact database we use. It could be SQL server, it could be a text file. So we want an abstraction layer shielding the code from this knowledge. All we need to know is what such a repository looks like:

    public interface ICustomerRepository
    {
        Customer GetCustomer(int id);
        IEnumerable<Customer> FindCustomers(string beginningOfName);
    }
    

    We can now implement this interface for the data storage that we use:

    public class SqlServerCustomerRepository : ICustomerRepository
    {
        public Customer GetCustomer(int id)
        {
            using(SqlConnection connection = new SqlConnection(connectionString))
            {
                // code to fetch data and populate Customer objects go here
            }
        }
        // implementations of other members of ICustomerRepository
        // left out to keep code short. Just imagine they are here :)
    }
    

    Finally, when we want to use this code, we can have a factory create the concrete ICustomerRepository implementation to use:

    public static class RepositoryFactory
    {
        public static ICustomerRepository CreateCustomerRepository()
        {
            return new SqlServerCustomerRepository();
        }
    }
    

    …and in our code where we need the data:

    ICustomerRepository repository = RepositoryFactory.CreateCustomerRepository();
    IEnumerable<Customer> customers = repository.FindCustomers("A");
    

    This way, there is no hard coupling between the consuming code, and the particular kind of repository in use (except for in the factory method, but that is the one and only place where this knowledge exists). This makes it easy to replace the concrete repository implementation. This is also useful for testing, where you can easily create a mock repository returning hard coded results for given input, so that you can unit test the code that needs data from the repository.

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

Sidebar

Related Questions

Could some body explain me caching in asp.net? I am just confused on the
Could some body explain exception vs error in asp.net
Could some body pleases explain me how asp form is processed in asp.net. I
Possible Duplicate: What is a singleton in C#? could some body please explain me
I have some problems with this syntax. Could somebody explain to me what this
Possible Duplicate: Understanding @Protocols in Objective-C Could somebody explain what a protocol is in
Could somebody explain what I'm doing wrong in attempting to insert a new UITableViewCell?
Could somebody explain what is the meaning of DomHelper in google closure? What is
Could somebody explain to me the architecture behind chatroulette? I was thinking about a
Could somebody explain me how to map a one-to-zero association with hibernate (using mapping

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.