dependencies
dependencies copied to clipboard
Describe how Injector is better than constructor.
Injector is better than direct constructor call because you could easily redefine one dependency in tests on average level without coping the full constructor expression. Fake objects great. Mock is bad.
class Foo:
a = 2
class Bar:
Foo = Foo
def __init__(self):
self.foo = self.Foo()
class Baz:
Bar = Bar
def __init__(self):
self.bar = self.Bar()
# override this
class NewBaz(Baz):
class Bar(Baz.Bar):
class Foo(Baz.Bar.Foo):
a = 1
And imagine if NewFoo will need additional arguments!