forked from onionmccabbage/beyondAdvancedPythonApril2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_proxy.py
52 lines (47 loc) · 1.61 KB
/
my_proxy.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
import random
from abc import ABCMeta, abstractmethod
class Payment(metaclass=ABCMeta):
@abstractmethod
def do_pay(self):
pass
class Bank(Payment):
def __init__(self):
self.card = None
self.account = None
def __getAccount(self):
self.account = self.card # Assume card number is account number
return self.account
def __hasFunds(self):
print("Bank:: Checking if Account", self.__getAccount(), "has enough funds")
return bool(random.getrandbits(1)) # fast way to return boolean
def setCard(self, card):
self.card = card
def do_pay(self):
if self.__hasFunds():
print("Bank:: Paying the merchant")
return True
else:
print("Bank:: Sorry, not enough funds!")
return False
class DebitCard(Payment): # this is the proxy
def __init__(self):
self.bank = Bank()
def do_pay(self):
card = input("Proxy:: Swipe Card or Phone")
self.bank.setCard(card)
return self.bank.do_pay()
class You:
def __init__(self):
print("You:: I'll have a fruity flat iced chai salted spice with whipped cream")
self.debitCard = DebitCard()
self.isPurchased = None
def make_payment(self):
self.isPurchased = self.debitCard.do_pay()
def __del__(self):
if self.isPurchased:
print("You:: mmmmmm yummie :-)")
else:
print("You:: can you lend me a fiver :(")
if __name__ == '__main__':
you = You()
you.make_payment()