Sometimes we develop several algorithms to get the same results. For example, I wrote a class that stores my data in trees, and another class that stores about the same data, for example, in linked lists.
I will publish an interface (abstract class) called ThingStore, and will subclass it into TreeThingStore and ListThingStore, each of which uses trees or linked lists.
However, since I am publishing an abstract class, I need someone to decide which implementation to use ( EDIT : so the caller does not care about this), and I have no problem that it is hardcoded. I needed this more than once, but I looked at GoF and other Design Patterns catalogs unconvincingly. The most similar picture is “Strategy”, but it achieves various goals.
So, is there a design template for this intention? If not, can someone create someone or tell me why this should not be done (or better ways to achieve the same results)?
source
share