Bryce-3D / Discord-Bot

Repository for any discord bots I make
2 stars 1 forks source link

Suboptimal Implementation of Status Codes #8

Open Bryce-3D opened 5 months ago

Bryce-3D commented 5 months ago

Currently it is annoying to have to use a chain of if and elif statements to handle the TTTStatusCodes.

Rough suggestion by htns to use polymorphism instead

@abstract
class Response:
    @abstract
    def getMessage()->str: …

class SuccessResponse(Response):
    def getMessage()->str:
        actual implementation here

class NotInLobbyResponse(Response):
    def getMessage()->str:
        actual implementation here

class Lobbies:
    def place(…) → Response:
        if …:
            return SuccessResponse(…)
        else:
            return NotInLobbyResponse(…)