I have situation that 3 different instances with the same method signature are doing their job repeatedly.
interface IArgs{
//args stuff
}
interface IExample{
void Populate(IArgs);
}
class ExampleA : IExample
{
void Populate(IArgs a){
//todo
}
}
class ExampleB : IExample
{
void Populate(IArgs b){
//todo
}
}
class ExampleC : IExample
{
void Populate(IArgs c){
//todo
}
}
class MainExampleClass(){
ExampleA classA;
ExampleB classB;
ExampleC classC;
//instantiation and other class stuff
foreach(Data data in dataCollection){
classA.Populate(data);
classB.Populate(data);
classC.Populate(data);
}
}
It's worth to mention that the classes work with different args
but I solve that with one dataholder class with all arguments and implementation of an interface (IArgs
).
So my question is: is there any good way, practice, pattern to solve this repeatedly calling of methods? The Factory pattern, if I understood, will return one instance, but here I need all 3.
Any suggestions would be appreciated.
IArgs
, but you seem to completely miss polymorphism forIExample
? Don't overthink this problem, simple array and foreach will solve your problem.