-
Notifications
You must be signed in to change notification settings - Fork 0
/
abstract_factory_account.py
76 lines (49 loc) · 2.06 KB
/
abstract_factory_account.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from __future__ import annotations
from abc import ABC, abstractmethod
class AbstractAccountFactory(ABC):
@abstractmethod
def create_savings_account(self) -> AbstractSavingsAccount:
pass
@abstractmethod
def create_credit_account(self) -> AbstractCreditAccount:
pass
class PlatinumAccountFactory(AbstractAccountFactory):
def create_savings_account(self) -> AbstractSavingsAccount:
return SavingsAccountPlatinum()
def create_credit_account(self) -> AbstractCreditAccount:
return CreditAccountPlatinum()
class GoldAccountFactory(AbstractAccountFactory):
def create_savings_account(self) -> AbstractSavingsAccount:
return SavingAccountGold()
def create_credit_account(self) -> AbstractCreditAccount:
return CreditAccountGold()
class AbstractSavingsAccount(ABC):
@abstractmethod
def confirm_savings_creation(self) -> str:
pass
class SavingAccountGold(AbstractSavingsAccount):
def confirm_savings_creation(self) -> str:
return "Saving Gold Created."
class SavingsAccountPlatinum(AbstractSavingsAccount):
def confirm_savings_creation(self) -> str:
return "Saving Platinum Created."
class AbstractCreditAccount(ABC):
@abstractmethod
def confirm_credit_creation(self) -> str:
pass
class CreditAccountGold(AbstractCreditAccount):
def confirm_credit_creation(self) -> str:
return "Credit Gold Created."
class CreditAccountPlatinum(AbstractCreditAccount):
def confirm_credit_creation(self) -> str:
return "Credit Platinum Created."
def client(factory: AbstractAccountFactory) -> None:
savings_acc = factory.create_savings_account()
credit_acc = factory.create_credit_account()
print(f"{savings_acc.confirm_savings_creation()}")
print(f"{credit_acc.confirm_credit_creation()}")
if __name__ == "__main__":
print("\nClient: Testing client code with Platinum Account Factory:")
client(PlatinumAccountFactory())
print("\nClient: Testing client code with Gold Account Factory:")
client(GoldAccountFactory())