I am challenging my OO design skills and started an ambitious project that is supposed to be highly reusable and extensible. It is supposed to be kind of a framework for evolutionary algorithms. Maybe there is somthing out there on GitHub, but my research didn't come up with anything I'm looking for and anyway, I'd like to see if I could develop it myself and improve my skills.
The very problem I'm facing is the multitude of potential interfaces I can imagine I or some potential user might need, because implementations of the objects are so different they even have different interfaces. That might sound strange or like bad design, but I think it's due to the meta level I'm thinking at. Let me give you an abstract example, maybe you spot the right pattern I'm missing. The current pattern is Strategy Pattern, but the interface will vary according to different DataInterfaces:
class Client {
/** EvaluatorInterface */
private $evaluatorStrategy;
public function getData(): DataInterface {
//return data...
}
public function doEvaluation()
{
$value = $this->evaluatorStrategy->evaluate($this->getData());
//...
}
}
The problem is, that in this client code, I do not exactly know, what the DataInterface and thus the EvaluatorInterface must look like, since I want to be able to both change the type the data is stored in and the strategy the evaluator works with. What I do know, is that the both need to match. E.g. When I decide to add a new fancy data structure with a new interface, I need to adjust the injected EvaluationStrategy accordingly.
So, since this is PHP I could just don't specify any types and just hope we have data and evaluator strategies that can work together, or otherwise we get a runtime error but that's not what I want. The design should be clean, and I think it must work somehow.
Another thing I tried was Visitor Pattern. At first it sounded promising, but then I realized, that the EvaluatorInterface would need grow each time I'd add a new data type, something a user of my package couldn't even do.
Do you have any ideas where I'm barking up the wrong tree? Or what pattern could help me?
EvaluatorInterfaceandDataInterfaceshould have one single data type that they operate on, and those should be the same type, i.e. you would prefer if php had generics?Client<SpecialDataInterface><SpecialEvaluatorInterface>. But I thought there might be a way without "fancy" language features and just simple, well considered OO Design ;)