Skip to content
loading...

re: Using the Strategy Pattern (Examples in C#) VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Could you make an example?
 

Sure.

Instead of inheriting from a base class and method overriding like here:

public class MyClass:BaseClass
{
    public override void Foo()
    {
       base.Foo();
    }
}

You add the class variable of a given class and calls it's method if needed.

public class MyClass
{
    private BaseClass _baseClass = new BaseClass();

    public void Foo()
    {
       _baseClass.Foo();
    }
}

More about the comparison between Inheritance and Composition you can find here. Take a closer look at the table at the end of article.

code of conduct - report abuse