Say I have the following interface:
ICarProvider
And the following classes implementing it:
RedCarProvider:ICarProvider
BlueCarProvider:ICarProvider
GreenCarProvider:ICarProvider
Now, what I would like to do is this:
Depending on the settings of the user, create a single instance of one (only one) of these classes and use that throughout the entire session of the application. So my logic should only know the interface and where to get the instance.
Is there a pattern for this?
Thanks!
It’s called the factory pattern.