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

The Archive Base Latest Questions

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

A simple interview question. How do interfaces help with code reusablity?

  • 0

A simple interview question.
How do interfaces help with code reusablity?

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

    An interface decouples the consumer from the implementation details of a class. This helps enables reusability because the class implementing an interface can change, without needing to change the code consuming the implementation.

    That’s very confusing, maybe an example helps

    public interface IUserAuthentication
    {
       public bool Authenticate(string name, string password);
    }
    

    Now I will write the consumer, it doesn’t care how authentication is performed, it simply knows that it can authenticate users.

    public class Consumer
    {
      private IUserAutentication _auth;
      public Consumer(IUserAuthentication auth) 
      {
       _auth = auth; 
      }
    
      public void Working(string username, string password) 
      {
        if (!_auth.Authenticate(username, password)) 
        {
           throw new Exception("error!");
        }
      }
    }
    

    The code above will work regardless of the implementation of the IUserAuthentication service. This is one way to reuse code.

    Now I can implement the IUserAuthentication interface

    public class AuthenticateJasons : IUserAuthentication
    {
      public bool Authenticate(string username, string password) 
      {
        return username == "Jason";
      }
    }
    
    public class AuthenticateNoone: IUserAuthentication
    {
      public bool Authenticate(string username, string password) 
      {
        return false;
      }
    }
    

    The point is that these implementations are irrelevant as far as the consumer is concerned. Also, this question is not related to ASP.NET the web framework. This is really a language/platform/framework agnostic question. The answer is the same regardless of the language you choose to implement with.

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

Sidebar

Related Questions

I faced a rather simple question in an interview. Why do we use the
I was doing interview question on priority queues and have a simple question I
I am trying to code a trival interview question of reversing a string. This
I'm inventing interview questions that require analysis of C++ code that does something simple
I had an interview and a question that seems really simple was not clicking
I am trying to write a simple program for this interview question: Write a
At the outset this looks pretty simple, however this was an interview question and
Alleged interview question and answer here . Will the following code compile (in C)?
So in an interview, I was actually asked a simple question that goes like
Simple question, but one that I've been curious about...is there a functional difference between

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.