This is a slightly abstract question about finding a pretty design approach with minimal boilerplate.
Prerequisites:
- I have an ENUM class for enumerating various providers i.e.:
enum class Provider { Google, Microsoft }
- Let’s say there is a service interface
interface Foo { fun getMail(): Mail }
that will be implemented for each specific provider.
I was curious if there is a way to define ENUM class Provider
in such way that it’s implementing interface Foo
and I can later specify by which objects each concrete provider will be implemented?
I wonder if there can be a boilerplate-less way to define enum class of concrete interface while I can later define by which objects concrete provider will be implemented.
Prerequisites aren’t solid so if a better design requires changes then I’m eager for a better suggestion.
Foo
implementation based on the enum key you provide to it? – PralineGoogle
andMicrosoft
being also aliases to some specific instances of corresponding services or simply delegate whole interface implementation to other objects (that more likely to be initialized later.) – Afterheat