An interface IFeatureParameters has no added value here. Whether or not a class (or whatever type you like) is a valid type to pass parameters to a feature, is entirely determined by the feature implementation. Every time a developer makes a new implementation of interface IFeature, they will specify explicitly what is the correct parameter type, by filling in the type variable T. That is enough to ensure no 'alien' types will be passed into an implementation of method Apply.
Here is a simple example.
public class FeatureParametersA { public string SomeText; } public class FeatureParametersB { public int SomeNumber; }
I could have made these classes implement an interface IFeatureParameters, but that is not required.
public interface IFeature<T> { CustomObject Apply(CustomObject obj, T par); } public class FeatureA : IFeature<FeatureParametersA> { public CustomObject Apply(CustomObject obj, FeatureParametersA par); { obj.Add(par.SomeText); return obj; } } public class FeatureB : IFeature<FeatureParametersB> { public CustomObject Apply(CustomObject obj, FeatureParametersB par); { obj.Add(par.SomeNumber.ToString()); return obj; } }
Notice how each class has its own dedicated implementation of Apply, specific for the related 'parameters' type. Everything is strongly typed, so the compiler will prevent anyone from trying to pass the wrong type into Apply.
For completeness:
public class CustomObject { public void Add(string s) { _sb.AppendLine(s); } private StringBuilder _sb = new StringBuilder(); }
IFeatureParametershas neither properties nor methods, why doesApplyeven care?IFeatureitself even meaningful? Without the interface it essentially reduces toobject Apply(object, object), which suggests absolutely nothing about how it should be implemented or used. If used only in a few places (or even just one) it sounds like the sort of thing a single well placedFuncmight also do.IFeatureandIFeatureParametersand bind them together. And to force others who write implementations of those interfaces to implement both interfaces for one purpose. To avoid situations whenOneFeatureParamersare passed intoAnotherFeature.Apply