7 ms·
I was going to propose the same thing with code: class MyDep: def do_foo(self): print("fooo!") class Fooser: def __init__(self, foo_
by necovek 5y ago
I was going to propose the same thing with code:
class MyDep:
def do_foo(self):
print("fooo!")
class Fooser:
def __init__(self, foo_dooer: MyDep):
self.foo_dooer = foo_dooer
def act(self):
self.foo_dooer.do_foo()
class FakeDep(MyDep):
def do_foo(self):
print("booo!")
# With the grand unveiling:
fooser = Fooser(MyDep())
Seems a lot simpler than 100 lines they brag about, yet this includes the business logic implementation for the code as well (dependency injection takes a couple of lines total; if you add interface handling or defaults, you'll add a few lines).