I'm wondering if there's a standardized name for the following refactoring:
class Foo: def do_something_awesome(self): my_bar = Bar(42) return my_bar.reticulate_splines()
Foo is explicitly coupled to class
Bar because it relies on that class name to create the
my_bar object. If I don't like this explicit coupling, I'd go
class Foo: def __init__(self, bar_generator): self.bar_generator = bar_generator def do_something_awesome(self): my_bar = self.bar_generator.create_bar(42) return my_bar.reticulate_splines()
I can swear I read this in either Martin Fowler's refactoring book or in Kerievski's refactoring to pattern book, but can't seem to find it.
Apart from that, would this be considered a reasonable refactoring? I feel it's a mix of Factory Object and Dependency Injection.