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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:13:53+00:00 2026-05-16T16:13:53+00:00

I am going over some OO basics and trying to understand why is there

  • 0

I am going over some OO basics and trying to understand why is there a use of Interface reference variables.

When I create an interface:

public interface IWorker
    {
        int HoneySum { get; }

        void getHoney();
    }

and have a class implement it:

public class Worker : Bee, IWorker
    {
        int honeySum = 15;

        public int HoneySum { get { return honeySum; } }

        public void getHoney()
        {
            Console.WriteLine("Worker Bee: I have this much honey: {0}", HoneySum);
        }
    }

why do people use:

IWorker worker = new Worker();
            worker.getHoney();

instead of just using:

Worker worker3 = new Worker();
            worker3.getHoney();

whats the point of a interface reference variable when you can just instatiate the class and use it’s methods and fields that way?

  • 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-16T16:13:53+00:00Added an answer on May 16, 2026 at 4:13 pm

    If your code knows what class will be used, you are right, there is no point in having an interface type variable. Just like in your example. That code knows that the class that will be instantiated is Worker, because that code won’t magically change and instantiate anything else than Worker. In that sense, your code is coupled with the definition and use of Worker.

    But you might want to write some code that works without knowing the class type. Take for example the following method:

    public void stopWorker(IWorker worker) {
        worker.stop(); // Assuming IWorker has a stop() method
    }
    

    That method doesn’t care about the specific class. It would handle anything that implements IWorker.

    That is code you don’t have to change if you want later to use a different IWorker implementation.

    It’s all about low coupling between your pieces of code. It’s all about maintainability.

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

Sidebar

Related Questions

I'm going over some C++/CLI material and I've come across the concept of a
I've been going over this in my head and trying out different approaches for
Been going over my predecessor's code and see usage of the request scope frequently.
I've been going over and over this in my head, and I can't seem
When I iterate over the values or keys are they going to correlate? Will
When creating an index over a column that is going to be UNIQUE (but
I've switched over to a Mac recently and, although things have been going quite
I'm doing some basic database learning on Oracle 11g over a Citrix client. The
I'm slowly going mad over the following problem: In my ASP.NET page (target: .NET
Let's say I have some class X that is going to be injected all

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.