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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:28:11+00:00 2026-05-27T00:28:11+00:00

Straight to the problem: I have a class that implements two interfaces: public class

  • 0

Straight to the problem: I have a class that implements two interfaces:

public class A : Interface1, Interface2{
   // Interface 1 implementation...
   // Interface 2 implementation...
}

Is there a way (without creating another new class) to make Interface1 implementation internal and hide it from other components (only Interface2 will stay public)?

EDIT: Some more useful infos: Interface1 and Interface2 are defined as public in another core component and cannot be changed.

Thanks in advance,

  • 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-27T00:28:12+00:00Added an answer on May 27, 2026 at 12:28 am

    While you can make the interface itself internal, the methods would still be part of the public API. What you can elect to do is explicit interface implementation, so that the API defined by the interface is only visible via the interface, and not via the class.

    interface IFoo
    {
         void M();
    }
    
    interface IBar
    {
         void X(); 
    }
    
    public class Bar : IBar, IFoo
    {
        public void X() // part of the public API of Bar
        {
        }
    
        void IFoo.M() // explicit implementation, only visible via IFoo
        {
        }
    }
    
    Bar bar = new Bar();
    bar.X(); // visible
    bar.M(); // NOT visible, cannot be invoked
    IFoo foo = bar;
    foo.M(); // visible, can be invoked
    

    Beyond this, if you need the world to never have any idea that the class supports the interface, then you would simply need to not have the class implement the interface. Interfaces are for the intent of broadcasting that a given object supports given behaviors, explicitly or otherwise. If that’s not what you want, you need to go a different direction. It could simply be that the class implements the behaviors as private implementation details, sans interface. Another approach is to shovel those implementations into a private nested class.

    public class Bar : IBar
    {
        Foo foo = new Foo();
    
        public void X() { }   
    
        public void DoSomething()
        {
            this.foo.M(); // invokes method of instance of nested class
        }
    
        class Foo : IFoo
        {
            public void M() { } 
        }
    }
    

    Under this approach, the world never knows that a class fulfills the interface contract, because it technically doesn’t. The contract is fulfilled by Foo, and the world cannot see Foo. However, the benefit is that if the class needs to invoke externally defined methods that require the interface, it can still pass the nested class instance to those methods.

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

Sidebar

Related Questions

I have a fairly straight-forward sequential approval workflow that has an EnableModificationActivity that is
I have an abstract immutable base class that defines enforces child classes to be
I'm terribly bad at keeping MySQL queries straight, but that aside I have one
I have a JavaScript class that I have made and put it into its
Problem: I'd like to specify the main class in a jar file that I
I have a fairly straight-forward scenario that I am trying to solve but I'm
I have an object model that looks like this (pseudo code): class Product {
I've got a problem that I think is probably straight forward but I can't
Weird problem. I update the site CSS sheet and the changes show straight away
This should be straight forward for a guru. I don't have any code really

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.