-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDependencyInversion.py
More file actions
41 lines (29 loc) · 1.1 KB
/
DependencyInversion.py
File metadata and controls
41 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
DIP is basically the idea that high-level modules/implementations
should not depend on lower level modules/implementations.
"""
from abc import ABC
class Convertor(ABC):
def convert(self, from_currency, to_currency, amount):
pass
class AEDConversion(Convertor):
def convert(self, from_currency, to_currency, amount):
return amount * 20
class USDConversion(Convertor):
def convert(self, from_currency, to_currency, amount):
return amount * 77
class App:
def __init__(self, converter: Convertor):
self.convertor = converter
def start(self, from_currency, to_currency, amount):
return self.convertor.convert(from_currency, to_currency, amount)
to_currency = "INR"
amount = 100000
aed_convertor = AEDConversion()
app = App(aed_convertor)
from_currency = "AED"
print("From {} to {} = {}".format(from_currency, to_currency, app.start(from_currency, to_currency, amount)))
usd_convertor = USDConversion()
from_currency = "USD"
app = App(usd_convertor)
print("From {} to {} = {}".format(from_currency, to_currency, app.start(from_currency, to_currency, amount)))