I have a service which is an API client.
It's goal is to instantiate a concrete client you tell it (different providers), implement it's methods (createRequest
and doRequest
) and forward their call to the concrete client, so, it is a proxy
.
But also, it needs to persist the response of clients to a database in a transparent way (so, developer does not have to worry about it when using the service).
This way, I'm mixing 2 patterns (proxy and factory for concrete clients) and also adding the persistence responsibility to the service.
My boss told me today that if I don't strictly follow the pattern, then I'm doing something else, but I can't say it is X pattern.
Is it true? Should I strictly follow patterns?
Maybe I could separate the instantiation of concrete clients in a factory that follows a factory pattern, but then it would be adding more files for something I should keep simple and stupid, so I'm afraid that doing a factory would be over-engineering.
public function setClient(string $clientName) {
if (!isset($this->clients[$clientName])) {
throw new InvalidClientException('some error');
}
$this->clientInstance = new $this->clients[$clientName]();
}