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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:47:06+00:00 2026-05-26T18:47:06+00:00

I have an interface IFoo for which I want to provide a default implementation

  • 0

I have an interface IFoo for which I want to provide a default implementation Foo.
Foo can be used as a contained class/component by other classes that implement IFoo.

IFoo is used by several classes that mostly implement it by forwarding calls to Foo, but for some methods they may provide their own implementation.

Foo needs access to (private) members of the calling class.

Passing these members as arguments in method calls is not possible because they are not (and should not be) part of the IFoo interface.

Providing public properties to these members only for this purpose is unwanted because it would make the interfaces of the calling classes overly complex.

The question is: what is good design to give Foo access to these members or how is this normally achieved? Are there any known design patterns for this?

EDIT: inheritance is not an option because the classes that implement IFoo can’t inherit from the same class.

  • 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-26T18:47:07+00:00Added an answer on May 26, 2026 at 6:47 pm

    No inheritance you say? So basically your Foo class doesn’t need to implement IFoo, it just needs to make implementing IFoo easy. Why can’t you add some parameters to the methods, then? Something like this:

    OK, let’s see. Let me make up some methods to make sure I got this right:

    interface IFoo
    {
        void DisplayTime();
    }
    

    And your FooImplHelper (made static just for the purpose of this example, I don’t know if it makes sense in your case or not)

    public static FooImplHelper
    {
        public static void DisplayTime(int UTFOffiset)
        {
            Console.WriteLine(DateTime.UtcNow + TimeSpan.FromHours(UTFOffset));
        }
    }
    

    and the IFoo implementation

    public class MyClock: BaseClock, IFoo
    {
         public void DisplayTime()
         {
             FooImplHelper.DisplayTime(2);
         }
    }
    

    Does that make sense? If not, you’re going to have to give some more information.

    Itay,

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

Sidebar

Related Questions

I have a class Foo implementing the IFoo interface. I have a method taking
I have code internal interface IFoo { void foo(); } public class A :
If i have an interface: interface IFoo { int Offset {get;} } can i
Say I have an interface IFoo and I want all subclasses of IFoo to
Suppose I have this interface public interface IFoo { ///<summary> /// Foo method ///</summary>
Suppose we have: interface Foo { bool Func(int x); } class Bar: Foo {
I have object called Foo. Right now it implements IFoo which has a lot
Suppose I have an interface: IFoo<T1,T2> and a class Moo<T1> : IFoo<List<T1>, Stack<T1>> .
Suppose I have an interface IFoo with implementation classes VideoFoo , AudioFoo , and
If you have an Interface IFoo and a class Bar : IFoo , why

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.