forked from CatalinStefan/python-design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactory_method.py
More file actions
60 lines (38 loc) · 1.07 KB
/
Copy pathfactory_method.py
File metadata and controls
60 lines (38 loc) · 1.07 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from abc import ABC, abstractmethod
class Country:
pass
class USA(Country):
pass
class Spain(Country):
pass
class Japan(Country):
pass
class CurrencyFactory(ABC):
@abstractmethod
def currency_factory(self, country) -> str:
pass
class FiatCurrencyFactory(CurrencyFactory):
def currency_factory(self, country) -> str:
if country is USA:
return "USD"
elif country is Spain:
return "EUR"
else:
return "JPY"
class VirtualCurrencyFactory(CurrencyFactory):
def currency_factory(self, country) -> str:
if country is USA:
return "Bitcoin"
elif country is Spain:
return "Ethereum"
else:
return "Dogecoin"
if __name__ == '__main__':
f1 = FiatCurrencyFactory()
f2 = VirtualCurrencyFactory()
print(f1.currency_factory(USA))
print(f1.currency_factory(Spain))
print(f1.currency_factory(Japan))
print(f2.currency_factory(USA))
print(f2.currency_factory(Spain))
print(f2.currency_factory(Japan))