2016-10-19 19:28:49 +03:00
|
|
|
"""The Code, that demonstrates dependency injection pattern."""
|
2016-03-29 20:17:12 +03:00
|
|
|
|
|
|
|
|
2020-01-27 02:41:36 +03:00
|
|
|
class Service:
|
2016-03-29 20:17:12 +03:00
|
|
|
"""Some "Service"."""
|
|
|
|
|
|
|
|
|
2020-01-27 02:41:36 +03:00
|
|
|
class Client:
|
2016-03-29 20:17:12 +03:00
|
|
|
"""Some "Client" that uses "Service"."""
|
|
|
|
|
2016-06-02 20:26:37 +03:00
|
|
|
def __init__(self, service): # Service instance is injected into Client
|
2020-01-26 22:22:43 +03:00
|
|
|
"""Initialize instance."""
|
2016-03-29 20:17:12 +03:00
|
|
|
self.service = service
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-03-30 11:45:41 +03:00
|
|
|
service = Service() # Application creates Service instance
|
|
|
|
client = Client(service) # and inject Service instance into the Client
|