Created
November 22, 2023 01:15
-
-
Save BrunoBiz/b7ebde59bda0480ba9e8f1e2f55f8009 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
from abc import ABC, abstractmethod | |
class Sandwich(ABC): | |
# Classe Abstrata | |
def template_method(self) -> None: | |
self.add_bread() | |
self.cut_bread() | |
self.add_ingredients() | |
self.add_condiments() | |
self.grill_sandwich() | |
self.wrap_sandwich() | |
def cut_bread(self) -> None: | |
print("GERAL....: Cortar pão") | |
def wrap_sandwich(self) -> None: | |
print("GERAL....: Embrulhar sanduiche") | |
@abstractmethod | |
def add_bread(self) -> None: | |
pass | |
@abstractmethod | |
def add_ingredients(self) -> None: | |
pass | |
@abstractmethod | |
def add_condiments(self) -> None: | |
pass | |
@abstractmethod | |
def grill_sandwich(self) -> None: | |
pass | |
class Sandwich1(Sandwich): | |
def add_bread(self) -> None: | |
print("Sandwich1: Pão integral") | |
def add_ingredients(self) -> None: | |
print("Sandwich1: Presunto, Queijo, Tomate") | |
def add_condiments(self) -> None: | |
print("Sandwich1: Ketchup") | |
def grill_sandwich(self) -> None: | |
print("Sandwich1: Prensar") | |
class Sandwich2(Sandwich): | |
def add_bread(self) -> None: | |
print("Sandwich1: Pão de Forma") | |
def add_ingredients(self) -> None: | |
print("Sandwich1: Alface, Frango, Atum") | |
def add_condiments(self) -> None: | |
print("Sandwich1: Maionese") | |
def grill_sandwich(self) -> None: | |
print("Sandwich1: Natural") | |
def client_code(abstract_sandwich: Sandwich) -> None: | |
abstract_sandwich.template_method() | |
if __name__ == "__main__": | |
print("Sanduiche 1:") | |
client_code(Sandwich1()) | |
print('\n') | |
print("Sanduiche 2:") | |
client_code(Sandwich2()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment