2020-07-18 07:40:14 +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:
|
2020-07-18 07:40:14 +03:00
|
|
|
"""The Service."""
|
2016-03-29 20:17:12 +03:00
|
|
|
|
|
|
|
|
2020-01-27 02:41:36 +03:00
|
|
|
class Client:
|
2020-07-18 07:40:14 +03:00
|
|
|
"""The Client that uses the Service."""
|
2016-03-29 20:17:12 +03:00
|
|
|
|
2020-07-18 07:40:14 +03:00
|
|
|
def __init__(self, service): # The Service is injected into the Client
|
|
|
|
"""Initialize the Client."""
|
2016-03-29 20:17:12 +03:00
|
|
|
self.service = service
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-07-18 07:40:14 +03:00
|
|
|
service = Service() # Application creates the Service
|
|
|
|
client = Client(service) # and inject the Service into the Client
|