I have a question regarding SDK design patterns / best practices in PHP. I know that PHP isn't the best choice for such a job (and I grew to HATE it over the last weeks) but the project is PHP, so this is not up for discussion...
What I want to do: The SDK allows to retrieve certain datasets identified by $id from a directory service. This functionality is e.g. implemented in the class Dir in method get($id). Now maybe I as a developer using this SDK want to improve this by having a local db table caching such datasets. Meaning every time, I do a call to get(), the function should first check the local table and only if this fails query the server.
Now - I don't want the developer to implement this and then call his own code manually before calling the regular get(), because the SDK does a lot of calls to get() implicitly.
So my question is: Is there a design pattern that basically says "developer, you MAY implement a function here that does this caching thing, but if you don't do it, its also ok".
Obviously, this shouldn't involve messing with the code of the SDK, as it should be shipped as a PHAR - and by altering any classes of the SDK, you would end up having a real problem with updating said SDK.
Aucun commentaire:
Enregistrer un commentaire