2016-03-30 14:10:43 +00:00
|
|
|
"""The Code, that follows inversion of control principle."""
|
2016-03-29 17:17:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Service(object):
|
|
|
|
"""Some "Service"."""
|
|
|
|
|
|
|
|
|
|
|
|
class Client(object):
|
|
|
|
"""Some "Client" that uses "Service"."""
|
|
|
|
|
2016-06-02 17:26:37 +00:00
|
|
|
def __init__(self, service): # Service instance is injected into Client
|
2016-03-29 17:17:12 +00:00
|
|
|
"""Initializer."""
|
|
|
|
self.service = service
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-03-30 08:45:41 +00:00
|
|
|
service = Service() # Application creates Service instance
|
|
|
|
client = Client(service) # and inject Service instance into the Client
|