I have an abstract class as defined here:
public abstract class BaseClientService<T>
where T : ISubsetInfo
{
abstract T Extract(Superset superset);
}
This works well for all of my implementation, but now I am faced with an implementation that needs an additional argument in order to perform correctly.
eg
T Extract(Superset superset, int id)
I’m trying to find the most elegant solution, so am trying to avoid including the second argument as either nullable or optional, but I’m not sure if it is worth the effort…
I also though about wrapping the arguments in an object, and having that object include the id for the edgecase, but I think its making it more complex where I’m trying to make it simpler.
The important constraint for me is that I always have one method to call in the abstract class.
The solution I went for in the end was to introduce a new generic object to my design called Requirement which would be used to identify additional requirements for the operation:
This solution is much like Dialecticus’s proposal, but I prefer this one as my requirement is strongly typed. One could argue the overuse of Generics here, but now that it is in my project, its working like a charm.