I have a conceptual question about SW design.
I prepared the following example:
One abstract base class:
internal abstract class BaseFamilyObject
{
//
//...
//
internal abstract IEnumerable<Device> GetCompatibleDevices(OtherDeviceClass otherDevClass);
//
// other methods
//
}
Six object families inheriting from the base class:
internal class FamilyObjectA : BaseFamilyObject // 5 more families
{
//
// other methods
//
internal override IEnumerable<Device> GetCompatibleDevices(OtherDeviceClass otherDevClass)
{
// do something and return list
return new List<Device>();
}
//
//...
//
}
The method GetCompatibleDevices is basically implemented in all six object families. This method is called generically at different places without knowing which specific object is calling (template method pattern).
Now another family is to be added, which however requires another two parameters in the method as decision criterion in order to return the correct list.
I can make it easy for myself and add the parameters to the signature in the base class. But I don't feel comfortable with introducing those to the other families, that don't need/use them.
internal class FamilyObjectNew : BaseFamilyObject // 5 more families
{
//
// other methods
//
internal override IEnumerable<Device> GetCompatibleDevices(OtherDeviceClass otherDevClass, bool criteria1, bool criteria2)
{
// do something and return list
return new List<Device>();
}
//
//...
//
}
Do you have any other solutions for the problem? Maybe the basic decision of the template method pattern wasn't optimal?