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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:29:50+00:00 2026-05-19T14:29:50+00:00

I am having a dispute with another fellow programmer, over the scope of interfaces.

  • 0

I am having a dispute with another fellow programmer, over the scope of interfaces.

suppose we have the following:

public interface IFoo
{
    string Bar { get; set; }
}

public class SomeFoo: IFoo
{
    public string Bar { get; set; }

    public SomeFoo(string bar)
    {
        this.Bar = bar;
    }
}

public class Consumer
{
    public void DoSomething()
    {
        SomeFoo fooClassInstance = new SomeFoo("test");
        IFoo fooInterface = (IFoo)fooClassInstance;

        // do something with fooInterface.
    }
}

So the question is:
1. Is it possible the fooClassInstance to go out of scope before something else releases the fooInterface instance?

Some argue that the object (fooClassInstance) can go out of scope.

I believe that it cant. Sure, objects may or may not get disposed of by the GC when the GC decides that the object(s) are no longer in scope. However since Interfaces are by design an abstract contract whose members have to be implemented by the object that uses it, than an interface cannot lose its implementation so long as the interface is used. It’s not like a whole another object is created of type “interface”. The interface is merely a pointer to those abstract members of the implementor.

Can you guys help me resolve this dispute?

Thanks,

<bleepzter />
  • 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-19T14:29:51+00:00Added an answer on May 19, 2026 at 2:29 pm

    Uh, what do you mean by “lose its implementation”? That makes no sense. A type implements an interface, it cannot “unimplement” an interface.

    As far as your code example goes, the lifetime of the object allocated ends the instant it no longer has any roots (aka, is no longer reachable by the GC). A reference to it is a reference to it, regardless of the type of the reference (i.e. if the reference type is of some derived or parent type, it doesn’t matter).

    ISomething Sample() {
        Something s1 = new Something();
        s2.DoSomething(); // Assuming s is the only reference to s, then it no longer is
                          // rooted after this expression
    
        Something s2 = new Something();
        ISomething is1 = s2;
        s2 = null;
        is1.DoSomething(); // The reference remains valid and the lifetime of the
                           // object created continues until we release all
                           // remaining references to it.
        return is1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

having another short regex problem. Basically I have a string like such: cn=WSG-AP-LO-COMMON-SITE-APPS,ou=ZFD,ou=SVC,ou=IGH I'm
Having the following class: public class SomeClass { private readonly int[] _someThings; public SomeClass()
I'm having a dispute with a colleague of mine. She says that the following:
Having the following code, how can I have get receive a map, and return
Having an assembly which I cannot modify (vendor-supplied) which have a method returning an
I'm having an internal dispute about the right way to do something. Maybe you
having a file with the following for example: DEFINE('INTERESTS_1','a'); DEFINE('INTERESTS_2','d'); DEFINE('INTERESTS_3','g'); DEFINE('INTERESTS_4','c'); Is it
Having the following code: int main(int argc, char* argv[]) { // program code std::cout
I am having a discussion with someone about the following table that is used
Having the following code: template<typename T, typename OutStream = std::ostream> struct print { OutStream

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.