python-dependency-injector/examples/ioc_di_demos/car_engine_ioc.py

19 lines
454 B
Python
Raw Normal View History

2016-06-02 20:26:37 +03:00
"""Refactored Car & Engine example that demonstrates inversion of control."""
2016-04-01 10:47:09 +03:00
class Engine(object):
"""Example engine."""
class Car(object):
"""Example car."""
def __init__(self, engine):
"""Initializer."""
2016-05-29 17:33:31 +03:00
self.engine = engine # Engine is an "injected" dependency
2016-04-01 10:47:09 +03:00
if __name__ == '__main__':
2016-04-26 13:14:39 +03:00
engine = Engine() # Application creates Engine's instance
car = Car(engine) # and inject it into the Car's instance