Last active
May 6, 2021 11:39
-
-
Save ApppleTurnover/65399a8a9a5c23b923435f8a77c58a6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Model | |
class Vessel: | |
def __init__(self, volume, type_drink): | |
self.volume = volume | |
self.type_drink = type_drink | |
class Bottle(Vessel): | |
def __init__(self, volume, type_drink): | |
super().__init__(volume, type_drink) | |
class Entity: | |
def __init__(self, name, volume): | |
self.name: str = name | |
self.volume: int = volume | |
self.last_drink = None | |
class Human(Entity): | |
def __init__(self, name): | |
super().__init__(name, 100) | |
# Control | |
def _drink(entity: Entity, vessel: Vessel, volume): | |
vessel.volume -= volume | |
entity.volume += volume | |
entity.last_drink = vessel.type_drink | |
return { | |
"volume": volume, | |
"type_drink": entity.last_drink, | |
"vessel_volume": vessel.volume | |
} | |
# View | |
def drink(entity: Entity, vessel: Vessel, volume): | |
request = _drink(entity, vessel, volume) | |
return f"{entity.name} drank {request.get('volume')} " \ | |
f"litters of {request.get('type_drink')}. " \ | |
f"There’s still {request.get('vessel_volume')} " \ | |
f"liters left in the {vessel.__class__.__name__}." | |
human = Human('Jorge') | |
bottle = Bottle(10, 'Water') | |
print(drink(human, bottle, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment