forked from Sean-Bradley/Design-Patterns-In-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdispenser50.py
More file actions
24 lines (19 loc) · 700 Bytes
/
Copy pathdispenser50.py
File metadata and controls
24 lines (19 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"A dispenser of £50 notes"
from interface_dispenser import IDispenser
class Dispenser50(IDispenser):
"Dispenses £50s if applicable, otherwise continues to next successor"
def __init__(self):
self._successor = None
def next_successor(self, successor):
"Set the next successor"
self._successor = successor
def handle(self, amount):
"Handle the dispensing of notes"
if amount >= 50:
num = amount // 50
remainder = amount % 50
print(f"Dispensing {num} £50 note(s)")
if remainder != 0:
self._successor.handle(remainder)
else:
self._successor.handle(amount)