Created
October 26, 2024 12:15
-
-
Save brablc/8b68cebcd6c87a5e148d0440d059e47f to your computer and use it in GitHub Desktop.
Pure Halloween 2024
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
# Stingy Jack Refactoring | |
# Good code doesn't need comments ... | |
# ... this dress code does | |
from matrix import BusinessSmart | |
from halloween import Lantern, PumpkinLantern | |
from typing import Protocol | |
__author__ = "Ondrej" | |
__version__ = "Halloween 2024" | |
__status__ = "on-boarding" | |
class BasketballLantern(Lantern): | |
"""When you don't have a pumpkin handy...""" | |
def light_up(self) -> str: | |
return "Sporty orange glow" | |
class BlacksmithCapable(Protocol): | |
"""What makes one Smith-like""" | |
def forge_tricks(self) -> str: | |
"""Ability to trick and forge""" | |
pass | |
class StingyJackRole(BlacksmithCapable): | |
"""The cursed one""" | |
def __init__(self, lantern: Lantern = PumpkinLantern()): | |
self.accessory = lantern | |
def forge_tricks(self) -> str: | |
return f"Tricking the devil by {self.accessory.light_up()}" | |
def curse(self) -> str: | |
return "Cursed to wander between worlds" | |
class AgentSmithRole(BlacksmithCapable): | |
"""Matrix abilities""" | |
dress: BusinessSmart = BusinessSmart.BLACK | |
def forge_tricks(self) -> str: | |
return "Tricking the Matrix" | |
def replicate(self) -> str: | |
return "Virus spreading through the Matrix" | |
class StingyOndrej: | |
"""Halloween Dress Code Documentation | |
Role: Multiple roles implementation | |
Architecture: | |
- StingyJackRole (The cursed one with lantern) | |
- AgentSmithRole (The one in black suit) | |
Both implementing BlacksmithCapable protocol | |
Known Bugs: | |
- Facial hair not matching original spec | |
- Using basketball as lantern | |
- Memory leak in sunglasses (they keep dropping) | |
- Random Agent voice failure after drinks | |
""" | |
def __init__(self): | |
self.jack_role = StingyJackRole(BasketballLantern()) | |
self.agent_role = AgentSmithRole() | |
def act_as_jack(self) -> str: | |
return self.jack_role.forge_tricks() | |
def act_as_agent(self) -> str: | |
return self.agent_role.forge_tricks() | |
def __str__(self): | |
return "I've been expecting you..." | |
# If you like this joke, you should retire and become a farmer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment