I'm trying to rewrite some code to break some coupling issues and make it easier to modify in the future.
Right now, I have a static factory method in a base class that, depending on the situation, picks an appropriate implementation. The decision is based on degrees of specialization:
While types A and B both can handle this, B was designed specifically for this situation and is the correct choice.
The base class is therefore intimately coupled with all implementations and this method must be rewritten when new specialized implementations are created.
I'm thinking about using the Chain of Responsibility pattern to break this coupling. However, I cannot see a way of ensuring that the most qualified implementation executes. If I give it over to the implementations to make this determination, I cannot guarantee they will be queried in order of specialization without encountering the same coupling issues.
Are there any patterns or methods for handling situations like this? (My best guess would hinder deployment; I'll keep it in my back pocket lest everybody say "yeah, that's the only way to do it!")