This question is somewhat inspired by a previous question I've asked.
Most of the code I write has to do with an API, which by its nature has to be easily extendible. A common problem that I and the rest of my team wrestle with his how to handle plugins, i.e classes that may extend our own interfaces and in the final implementation should feel like an atomic part of the solution. I'm thinking in particular in the following kind of use case (to use a car analogy)
Interface:
Car
Provided Implementations:
Ford
Audi
3rd Party Implementations:
Toyota
What we usually require is that the class CarDealer
be aware of all existing implementations of Car
without the 3rd party being forced to explicitly declare Car
in a configuration file. One idea I've been toying with is to let implementations of Car
register themselves with CarDealer
, but this opens up a new can of worms because Toyota
(or any other implementation) won't be initialized until they're explicitly referenced, which is a catch22. Annotating implementations of Car
and then going through the code and initializing any class with the relevant annotation is also a way to go, but I'm afraid that this might be terribly resource heavy.
I figure that we can't be the first ones with this issue, so are there any known design patterns to solve it out there?