My impression is that in “modern” OOP, the factory pattern is somewhat discouraged and dependency injection is used instead.
That means components don’t “ask” for dependencies. Instead, they receive their dependencies during construction. And there is a point in the code, sometimes called the “composition root” where all the dependencies of all components are wired together. This wiring can be done by just passing arguments around, but you can add some degreee of magic to automate things somewhat.
So, in the case of Logger
vs. FileLogger
, the change from MyFileLogger
to _logger . MkFileLogger
would be in the composition root, not on any component that uses Logger
. The composition root would have to be recompiled, but not the clients of Logger
(which could live in a separate compilation unit).