0

I am having a class implement two (or more) separate interfaces:

public class Demo : IInterface1, IInterface2
{
    ...
}

Then at some point, I need to call a method (or constructor) depending on these two distinct roles:

public void Method(IInterface1 parameter1, IInterface2 parameter2)
{
    ...
}

I am reaching a point in my code, where I will have to do:

Demo obj = new Demo(...);
Method(obj, obj);

Does this specific construct have a name (of sorts)? Is this problematic? Is it a familiar problem and what, if any, is the recommended way to "refactor" around this?

The only suitable thing that comes to mind is to combine the two interfaces in a single one and use this wherever I need both roles, but it might be the case that different objects will end up playing each role in the end. Should I stick with passing the same object as more than one arguments of a method/constructor?

put on hold as too broad by Doc Brown, gnat, BobDalgleish, Greg Burghardt, Bart van Ingen Schenau 1 hour ago

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Yes, it means your class is probably violating the single responsibility principle if it has "both roles". – Telastyn Sep 10 at 2:18
  • 2
    Questions with anonymous function and class names like Foo, Bar (or Demo, Method, IInterface) are usually too unspecific, because they lack context and ask for things which require knowledge of the semantics of the code, only providing formal structure is not enough for a sensible answer. Currently, I think the only answer I could give here is "It depends" (and no, this does not have a name). – Doc Brown Sep 10 at 2:48