2016-04-26 10:14:39 +00:00
|
|
|
"""Refactored Car & Engine example that demostrates inversion of control."""
|
2016-04-01 07:47:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Engine(object):
|
|
|
|
"""Example engine."""
|
|
|
|
|
|
|
|
|
|
|
|
class Car(object):
|
|
|
|
"""Example car."""
|
|
|
|
|
|
|
|
def __init__(self, engine):
|
|
|
|
"""Initializer."""
|
|
|
|
self.engine = engine
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-04-26 10:14:39 +00:00
|
|
|
engine = Engine() # Application creates Engine's instance
|
|
|
|
car = Car(engine) # and inject it into the Car's instance
|