lundi 1 mai 2017

Is there a pattern for extending a base class with children that implements an interface?

Lets say I have 2 classes that implements the same interface:

public interface IDoSomething
{
    void DoSomething();
}

public class Child1
{
    private const int CONST1 = 0;

    void IDoSomething.DoSomehting()
    { /*Do something the way a Child1 would*/ }
}

public class Child2
{
    private const int CONST1 = 0;

    void IDoSomething.DoSomehting()
    { /*Do something the way a Child2 would*/ }
}

What I want to know is since both class uses the same constant (CONST1) should I create a new class something like:

public class Parent
{
    private const int CONST1 = 0;
}

and then make Child1 and Child2 inherit from that class assuming that the real classes in this scenario is bigger (has more then one constant and more than one function implemented through the interface)?

Aucun commentaire:

Enregistrer un commentaire