Command Pattern

# Command Pattern is good for batch processes with behavioral classclass Document: text = "" def __str__(self): return self.textimport abcclass DocumentCommand(abc.ABC): doc = None @abc.abstractmethod def execute(self): pass @abc.abstractmethod def…

Continue ReadingCommand Pattern

Composite Pattern

import abcclass IMenu(abc.ABC): def __init__(self, title): self.text = title def traverse(self, prefix): print(f"{prefix} {self.text}") if hasattr(self, "components"): for menu in self.components: menu.traverse(prefix + prefix)class Menu(IMenu): def __init__(self, title): super().__init__(title) self.components…

Continue ReadingComposite Pattern