Skip to content

Instantly share code, notes, and snippets.

@ApppleTurnover
Last active May 6, 2021 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ApppleTurnover/65399a8a9a5c23b923435f8a77c58a6e to your computer and use it in GitHub Desktop.
Save ApppleTurnover/65399a8a9a5c23b923435f8a77c58a6e to your computer and use it in GitHub Desktop.
# 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