Consider the following example:
struct Client
{
void f()
{
s.registerCallback(std::bind(&Client::callback(), this));
s.foo();
}
void callback()
{
std::cout << "called back" << std::endl;
}
// library class
Service s;
};
Now, I have found a bug in Service, and want to put in a work-around in my client code. the workaround involves additional processing in f() and callback(). Let's also say that I Service in many parts of my code and I don't want to make the same changes everywhere.
Would a good solution be to simply subclass Service to a new class ServiceWithWorkaround, introduce the work-around logic in the overridden foo() and registerCallback() calls, and replace instances of Service with ServiceWithWorkaround wherever I need the workaround, until the vendor fixes the bug?
Assume that Service has quite an extensive interface and I do not want to use a decorator pattern and implement and forward the entire Service interface. Is there a better pattern that I can use here to solve this problem?
Aucun commentaire:
Enregistrer un commentaire