broken down as simple as possible:
Is there a design pattern (name) for the following scenario?
There could be many general purpose Generators available implementing the IGenerator interface, but also some country-dependent ones (extending GeneratorBase). The latter can encapsulate country-dependent generators as well as country-independent generators, depending on the type of "SomeType" to hold an implementation for. Mehtod init()
is meant to be overriden containing registration / mapping process of available generators.
The abstract class GeneratorBase provides functionality for associating and looking up generators for a certain type of "SomyType". In parallel there can IGenerator implementations exist, which are neither aware of "SomeType" or a country.
side note: All usable (not available!) generators are maintained in a separate registry class, which is responsible for looking up the right IGenerator implementation.
The only Interface the client/user gets is the IGenerator interface.
public interface IGenerator
{
public String generate(SomeType s);
}
public abstract class GeneratorBase implements IGenerator
{
private Map generators;
protected String country;
public GeneratorBase(String country){
generators = new HashMap();
this.country = country;
init();
}
public abstract void init();
public String generate(SomeType s)
{
Generator gen = (Generator) generators.get(new Integer(s.getObjectType()));
...
return gen.generate(s);
}
}
Edit: I have come across the Adapter Pattern, Bridge Pattern and Decorator Pattern. None of them really fits this setting. The closest ones could be the Adapter or Bridge Pattern, but neither am I adapting something, nor bridging (abstract class is implementing exactly same interface as implementors)