in real life it doesn't really make sense to bind IEngine to HondaEngine
Well, in some cases it might make sense. If you were, for example, building a multi-tenant / white-label app for the automotive industry (which I've done before) it might make sense to bind a concrete implementation of IEngine at app startup.
But yes, in other cases, when using late binding, then a factory could work.
You could also use the strategy pattern in conjunction with the DI container.
It's pretty neat! As long as your interface exposes some way to differentiate between each concrete implementation then you can just check that at run-time.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Well, in some cases it might make sense. If you were, for example, building a multi-tenant / white-label app for the automotive industry (which I've done before) it might make sense to bind a concrete implementation of
IEngine
at app startup.But yes, in other cases, when using late binding, then a factory could work.
You could also use the strategy pattern in conjunction with the DI container.
👍
That strategy pattern code is interesting. I had no idea you could do this:
It's pretty neat! As long as your interface exposes some way to differentiate between each concrete implementation then you can just check that at run-time.