Decorating a class with protected methods

c#, design-patterns

Solution

Protected methods are only visible to subclasses. If `Foo` and `Foo2` are in the same assembly you can make `Foo.Bar` internal instead:

public class Foo
{
    internal void Bar() { ... }
}

Problem

I want to do the exactly the same thing described here, but in C#. ``` public interface IFoo { void DoSomething(); } public class Foo : IFoo { public void DoSomething() {...} protected void Bar() {...} } public class Foo2 : IFoo { private readonly Foo _foo; public Foo2 (Foo foo) { _foo = foo; } public void DoSomething() {...} protected void Bar() { _foo.Bar(); // cannot access Bar() from here } } ``` I looked at several similar questions, but none of them really tell you exactly how to solve this problem. Is trying to decorate a class with protected method a wrong thing to do in the first place?

Original source

Related problems