├── observer ├── run.py └── src │ ├── interfaces │ ├── __init__.py │ └── observador.py │ ├── __init__.py │ ├── pessoa.py │ └── alarme.py ├── adapter ├── src │ ├── __init__.py │ ├── helper │ │ ├── __init__.py │ │ └── adapter.py │ ├── controller.py │ └── routes.py ├── chamada_http.py ├── framework_qualquer.py └── framework_qualquer2.py ├── singleton ├── src │ ├── __init__.py │ ├── singleton.py │ └── my_class.py ├── elemento2.py ├── start.py └── elemento1.py ├── facade └── models │ ├── __init__.py │ ├── __pycache__ │ ├── delete.cpython-38.pyc │ ├── insert.cpython-38.pyc │ ├── select.cpython-38.pyc │ ├── __init__.cpython-38.pyc │ ├── repo_facade.cpython-38.pyc │ └── repository_facade.cpython-38.pyc │ ├── delete.py │ ├── insert.py │ ├── select.py │ └── repository_facade.py ├── factory ├── controllers │ ├── __init__.py │ └── usecase.py ├── infra │ ├── __init__.py │ └── mysql.py ├── factorys │ ├── __init__.py │ └── usecase_factory.py ├── interface │ ├── __init__.py │ └── database_interface.py └── main.py ├── strategy ├── src │ ├── __init__.py │ ├── habilidades │ │ ├── __init__.py │ │ ├── interfaces.py │ │ ├── curar.py │ │ ├── luta_arco.py │ │ ├── luta_espada.py │ │ └── luta_marchado.py │ └── guerreiro.py └── run.py ├── chain-of-responsability ├── validators │ ├── interface │ │ ├── __init__.py │ │ └── validator_interface.py │ ├── __init__.py │ ├── nos_validator.py │ ├── carne_validator.py │ └── banana_validator.py └── main.py ├── command ├── commands │ ├── __init__.py │ ├── interface.py │ └── button_command.py ├── receptor.py ├── run.py └── button.py ├── decorator └── start.py └── template-method ├── run.py └── template.py /observer/run.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /adapter/src/__init__.py: -------------------------------------------------------------------------------- 1 | from .routes import route1 2 | -------------------------------------------------------------------------------- /adapter/src/helper/__init__.py: -------------------------------------------------------------------------------- 1 | from .adapter import Adapter 2 | -------------------------------------------------------------------------------- /singleton/src/__init__.py: -------------------------------------------------------------------------------- 1 | from .singleton import message 2 | -------------------------------------------------------------------------------- /facade/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .repository_facade import Repository -------------------------------------------------------------------------------- /factory/controllers/__init__.py: -------------------------------------------------------------------------------- 1 | from .usecase import UseCase 2 | -------------------------------------------------------------------------------- /factory/infra/__init__.py: -------------------------------------------------------------------------------- 1 | from .mysql import MysqlRepository 2 | -------------------------------------------------------------------------------- /factory/factorys/__init__.py: -------------------------------------------------------------------------------- 1 | from .usecase_factory import UseCaseFactory -------------------------------------------------------------------------------- /observer/src/interfaces/__init__.py: -------------------------------------------------------------------------------- 1 | from .observador import Observador -------------------------------------------------------------------------------- /factory/interface/__init__.py: -------------------------------------------------------------------------------- 1 | from .database_interface import DatabaseInterface 2 | -------------------------------------------------------------------------------- /singleton/elemento2.py: -------------------------------------------------------------------------------- 1 | from src import message 2 | 3 | el2 = message 4 | el2.say() -------------------------------------------------------------------------------- /observer/src/__init__.py: -------------------------------------------------------------------------------- 1 | from .alarme import Alarme 2 | from .pessoa import Pessoa 3 | -------------------------------------------------------------------------------- /adapter/chamada_http.py: -------------------------------------------------------------------------------- 1 | from framework_qualquer2 import post_http 2 | 3 | post_http() 4 | -------------------------------------------------------------------------------- /singleton/start.py: -------------------------------------------------------------------------------- 1 | from elemento1 import el1 2 | from elemento2 import el2 3 | 4 | el2.say() -------------------------------------------------------------------------------- /strategy/src/__init__.py: -------------------------------------------------------------------------------- 1 | from .guerreiro import Guerreiro 2 | from .habilidades import * 3 | -------------------------------------------------------------------------------- /singleton/src/singleton.py: -------------------------------------------------------------------------------- 1 | from .my_class import SaySomething 2 | message = SaySomething('Ola Mundo') -------------------------------------------------------------------------------- /chain-of-responsability/validators/interface/__init__.py: -------------------------------------------------------------------------------- 1 | from .validator_interface import ValidatorInterface -------------------------------------------------------------------------------- /command/commands/__init__.py: -------------------------------------------------------------------------------- 1 | from .interface import CommandInterface 2 | from .button_command import ButtonCommand -------------------------------------------------------------------------------- /adapter/src/controller.py: -------------------------------------------------------------------------------- 1 | def write_in_database(name, message): 2 | print('Writing in Database: {} {}'.format(name, message)) 3 | -------------------------------------------------------------------------------- /singleton/elemento1.py: -------------------------------------------------------------------------------- 1 | from src import message 2 | 3 | el1 = message 4 | el1.say() 5 | el1.change_message('Alterei a minha mensagem') -------------------------------------------------------------------------------- /facade/models/__pycache__/delete.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programadorLhama/Design-Patterns/HEAD/facade/models/__pycache__/delete.cpython-38.pyc -------------------------------------------------------------------------------- /facade/models/__pycache__/insert.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programadorLhama/Design-Patterns/HEAD/facade/models/__pycache__/insert.cpython-38.pyc -------------------------------------------------------------------------------- /facade/models/__pycache__/select.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programadorLhama/Design-Patterns/HEAD/facade/models/__pycache__/select.cpython-38.pyc -------------------------------------------------------------------------------- /facade/models/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programadorLhama/Design-Patterns/HEAD/facade/models/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /factory/main.py: -------------------------------------------------------------------------------- 1 | from factorys import UseCaseFactory 2 | 3 | usecase = UseCaseFactory.create() 4 | 5 | response = usecase.do_something(True) 6 | print(response) 7 | -------------------------------------------------------------------------------- /facade/models/__pycache__/repo_facade.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programadorLhama/Design-Patterns/HEAD/facade/models/__pycache__/repo_facade.cpython-38.pyc -------------------------------------------------------------------------------- /chain-of-responsability/validators/__init__.py: -------------------------------------------------------------------------------- 1 | from .banana_validator import BananaValidator 2 | from .carne_validator import CarneValidator 3 | from .nos_validator import NosValidator -------------------------------------------------------------------------------- /command/commands/interface.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | class CommandInterface(ABC): 4 | 5 | @abstractmethod 6 | def execute(self) -> None: 7 | pass -------------------------------------------------------------------------------- /observer/src/interfaces/observador.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | class Observador(ABC): 4 | 5 | @abstractmethod 6 | def update(self): 7 | pass 8 | -------------------------------------------------------------------------------- /facade/models/__pycache__/repository_facade.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programadorLhama/Design-Patterns/HEAD/facade/models/__pycache__/repository_facade.cpython-38.pyc -------------------------------------------------------------------------------- /factory/interface/database_interface.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | class DatabaseInterface(ABC): 4 | 5 | @abstractmethod 6 | def select_one(self): 7 | pass 8 | -------------------------------------------------------------------------------- /strategy/src/habilidades/__init__.py: -------------------------------------------------------------------------------- 1 | from .interfaces import Ihabilidade 2 | from .luta_espada import LutaEspada 3 | from .luta_arco import UsoArco 4 | from .curar import Curar 5 | from .luta_marchado import LutaMarchado -------------------------------------------------------------------------------- /facade/models/delete.py: -------------------------------------------------------------------------------- 1 | ''' from orm_ficticia import minha_orm ''' 2 | 3 | class Delete: 4 | 5 | def delete_single_element(self): 6 | ''' Codigo muito complexo, cheio de interações ''' 7 | print('deleta um registro') 8 | -------------------------------------------------------------------------------- /factory/factorys/usecase_factory.py: -------------------------------------------------------------------------------- 1 | from infra import MysqlRepository 2 | from controllers import UseCase 3 | 4 | class UseCaseFactory: 5 | 6 | @staticmethod 7 | def create() -> UseCase: 8 | return UseCase(MysqlRepository()) 9 | -------------------------------------------------------------------------------- /command/receptor.py: -------------------------------------------------------------------------------- 1 | class Receptor: 2 | 3 | def process_information(self, information: any) -> None: 4 | ''' Poderiamos usar aquela biblioteca Requests... ''' 5 | print('Enviando informacoes para backend!') 6 | print(information) 7 | -------------------------------------------------------------------------------- /command/run.py: -------------------------------------------------------------------------------- 1 | from button import Button 2 | from receptor import Receptor 3 | from commands import ButtonCommand 4 | 5 | recep = Receptor() 6 | butt = Button() 7 | 8 | butt.set_command(ButtonCommand(recep, { "ola": "mundo" })) 9 | butt.action() 10 | -------------------------------------------------------------------------------- /singleton/src/my_class.py: -------------------------------------------------------------------------------- 1 | class SaySomething: 2 | 3 | def __init__(self, message): 4 | self.message = message 5 | 6 | def say(self): 7 | print(self.message) 8 | 9 | def change_message(self, new_message): 10 | self.message = new_message 11 | -------------------------------------------------------------------------------- /strategy/src/habilidades/interfaces.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractclassmethod 2 | 3 | class Ihabilidade(ABC): 4 | 5 | @abstractclassmethod 6 | def comportamento(self): 7 | pass 8 | 9 | @abstractclassmethod 10 | def nivel_atributo(self): 11 | pass 12 | -------------------------------------------------------------------------------- /factory/infra/mysql.py: -------------------------------------------------------------------------------- 1 | from typing import Dict 2 | from interface import DatabaseInterface 3 | 4 | class MysqlRepository (DatabaseInterface): 5 | 6 | def select_one(self) -> Dict: 7 | return { 8 | "success": True, 9 | "data": 'Ola Mundo' 10 | } 11 | -------------------------------------------------------------------------------- /chain-of-responsability/validators/interface/validator_interface.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | class ValidatorInterface(ABC): 4 | 5 | @abstractmethod 6 | def validate(self, comida: str) -> bool: 7 | pass 8 | 9 | @abstractmethod 10 | def action(self) -> None: 11 | pass 12 | -------------------------------------------------------------------------------- /observer/src/pessoa.py: -------------------------------------------------------------------------------- 1 | from .interfaces import Observador 2 | 3 | class Pessoa(Observador): 4 | 5 | def __init__(self): 6 | self.acordada = False 7 | 8 | def esta_acordada(self): 9 | return self.acordada 10 | 11 | def update(self): 12 | print('Opa, acordei!') 13 | self.acordada = True 14 | -------------------------------------------------------------------------------- /chain-of-responsability/validators/nos_validator.py: -------------------------------------------------------------------------------- 1 | from .interface import ValidatorInterface 2 | 3 | class NosValidator(ValidatorInterface): 4 | 5 | def validate(self, comida: str) -> bool: 6 | if comida == 'nos': return True 7 | return False 8 | 9 | def action(self) -> None: 10 | print('O esquilo come a nos') -------------------------------------------------------------------------------- /chain-of-responsability/validators/carne_validator.py: -------------------------------------------------------------------------------- 1 | from .interface import ValidatorInterface 2 | 3 | class CarneValidator(ValidatorInterface): 4 | 5 | def validate(self, comida: str) -> bool: 6 | if comida == 'carne': return True 7 | return False 8 | 9 | def action(self) -> None: 10 | print('O Leao come a carne') -------------------------------------------------------------------------------- /strategy/src/habilidades/curar.py: -------------------------------------------------------------------------------- 1 | from .interfaces import Ihabilidade 2 | 3 | class Curar(Ihabilidade): 4 | 5 | def __init__(self, nivel): 6 | self.nivel = nivel 7 | 8 | def comportamento(self): 9 | print("Curar Personagem") 10 | 11 | def nivel_atributo(self): 12 | print('Nivel de Cura: {}'.format(self.nivel)) -------------------------------------------------------------------------------- /chain-of-responsability/validators/banana_validator.py: -------------------------------------------------------------------------------- 1 | from .interface import ValidatorInterface 2 | 3 | class BananaValidator(ValidatorInterface): 4 | 5 | def validate(self, comida: str) -> bool: 6 | if comida == 'banana': return True 7 | return False 8 | 9 | def action(self) -> None: 10 | print('O macaco come a banana') 11 | -------------------------------------------------------------------------------- /strategy/src/habilidades/luta_arco.py: -------------------------------------------------------------------------------- 1 | from .interfaces import Ihabilidade 2 | 3 | class UsoArco(Ihabilidade): 4 | 5 | def __init__(self, nivel): 6 | self.nivel = nivel 7 | 8 | def comportamento(self): 9 | print("Atirar flexas") 10 | 11 | def nivel_atributo(self): 12 | print('Nivel de uso Arco: {}'.format(self.nivel)) -------------------------------------------------------------------------------- /strategy/src/habilidades/luta_espada.py: -------------------------------------------------------------------------------- 1 | from .interfaces import Ihabilidade 2 | 3 | class LutaEspada(Ihabilidade): 4 | 5 | def __init__(self, nivel): 6 | self.nivel = nivel 7 | 8 | def comportamento(self): 9 | print("Lutar com espada") 10 | 11 | def nivel_atributo(self): 12 | print('Nivel de uso Espada: {}'.format(self.nivel)) 13 | -------------------------------------------------------------------------------- /strategy/src/habilidades/luta_marchado.py: -------------------------------------------------------------------------------- 1 | from .interfaces import Ihabilidade 2 | 3 | class LutaMarchado(Ihabilidade): 4 | 5 | def __init__(self, nivel): 6 | self.nivel = nivel 7 | 8 | def comportamento(self): 9 | print("Lutar com marchado") 10 | 11 | def nivel_atributo(self): 12 | print('Nivel de uso Espada: {}'.format(self.nivel)) -------------------------------------------------------------------------------- /strategy/run.py: -------------------------------------------------------------------------------- 1 | from src import Guerreiro, UsoArco, LutaEspada, Curar, LutaMarchado 2 | 3 | cavaleiro = Guerreiro(LutaEspada(6)) 4 | arqueiro = Guerreiro(UsoArco(9)) 5 | curandeiro = Guerreiro(Curar(7)) 6 | cavaleiroMarchado = Guerreiro(LutaMarchado(8)) 7 | 8 | cavaleiro.acao() 9 | arqueiro.acao() 10 | arqueiro.attributos() 11 | curandeiro.attributos() 12 | cavaleiroMarchado.acao() -------------------------------------------------------------------------------- /facade/models/insert.py: -------------------------------------------------------------------------------- 1 | ''' from orm_ficticia import minha_orm ''' 2 | 3 | class Insert: 4 | 5 | def insert_single_element(self): 6 | ''' Codigo muito complexo, cheio de interações ''' 7 | print('insere um unico registro') 8 | 9 | def insert_many_elements(self): 10 | ''' Codigo muito complexo, cheio de interações ''' 11 | print('insere varios registros') 12 | -------------------------------------------------------------------------------- /facade/models/select.py: -------------------------------------------------------------------------------- 1 | ''' from orm_ficticia import minha_orm ''' 2 | 3 | class Select: 4 | 5 | def select_single_element(self): 6 | ''' Codigo muito complexo, cheio de interações ''' 7 | print('retornando um unico registro') 8 | 9 | def select_many_elements(self): 10 | ''' Codigo muito complexo, cheio de interações ''' 11 | print('retorna varios registros') 12 | -------------------------------------------------------------------------------- /strategy/src/guerreiro.py: -------------------------------------------------------------------------------- 1 | from typing import Type 2 | from .habilidades import Ihabilidade 3 | 4 | class Guerreiro: 5 | 6 | def __init__(self, habilidade: Type[Ihabilidade]): 7 | self.habilidade = habilidade 8 | 9 | def acao(self): 10 | # Processamento 11 | self.habilidade.comportamento() 12 | 13 | def attributos(self): 14 | self.habilidade.nivel_atributo() 15 | -------------------------------------------------------------------------------- /command/button.py: -------------------------------------------------------------------------------- 1 | from commands import CommandInterface 2 | from typing import Type 3 | 4 | class Button: 5 | 6 | def __init__(self) -> None: 7 | self.__command = None 8 | 9 | def set_command(self, command: Type[CommandInterface]) -> None: 10 | self.__command = command 11 | 12 | def action(self) -> None: 13 | if self.__command: 14 | self.__command.execute() 15 | 16 | -------------------------------------------------------------------------------- /adapter/framework_qualquer.py: -------------------------------------------------------------------------------- 1 | from src import route1 2 | 3 | def post_http(): 4 | http_message = { 5 | "method": "POST", 6 | "header": { 7 | "token": "Bearer jioiaefi48904729kldan324", 8 | "origin": "http://something.other.org" 9 | }, 10 | "body": { 11 | "name": "Lhama", 12 | "message": "Hello Word" 13 | } 14 | } 15 | 16 | route1(http_message) 17 | -------------------------------------------------------------------------------- /decorator/start.py: -------------------------------------------------------------------------------- 1 | def decorator(funcao): 2 | def wrapper(*arg, **kwargs): 3 | print('Ola Mundo') 4 | print(arg[1]) 5 | print(kwargs) 6 | funcao(*arg, **kwargs) # print('Estou na minha classe') 7 | 8 | return wrapper 9 | 10 | 11 | class minha_classe: 12 | 13 | @decorator 14 | def metodo(self, num): 15 | print('Estou na minha classe') 16 | 17 | 18 | 19 | cl = minha_classe() 20 | cl.metodo(4) 21 | -------------------------------------------------------------------------------- /adapter/framework_qualquer2.py: -------------------------------------------------------------------------------- 1 | from src import route1 2 | 3 | def post_http(): 4 | http_message = { 5 | "HTTP_method": "POST", 6 | "HTTP_header": [ 7 | ("token", "Bearer jioiaefi48904729kldan324"), 8 | ("origin", "http://something.other.org") 9 | ], 10 | "HTTP_body": [ 11 | ("name", "Lhama"), 12 | ("message", "Hello Word") 13 | ] 14 | } 15 | 16 | route1(http_message) 17 | -------------------------------------------------------------------------------- /factory/controllers/usecase.py: -------------------------------------------------------------------------------- 1 | from interface import DatabaseInterface 2 | from typing import Dict, Type, Union 3 | 4 | class UseCase: 5 | 6 | def __init__(self, repository: Type[DatabaseInterface]) -> None: 7 | self.__repository = repository 8 | 9 | def do_something(self, data: bool) -> Union[Dict, None]: 10 | if data is True: 11 | repositoryResponse = self.__repository.select_one() 12 | return repositoryResponse 13 | return None 14 | -------------------------------------------------------------------------------- /chain-of-responsability/main.py: -------------------------------------------------------------------------------- 1 | from validators import CarneValidator, NosValidator, BananaValidator 2 | 3 | class Validacao: 4 | 5 | def __init__(self) -> None: 6 | self.val = [ 7 | BananaValidator(), 8 | NosValidator(), 9 | CarneValidator() 10 | ] 11 | 12 | def process(self, comida: str): 13 | for v in self.val: 14 | if v.validate(comida): return v.action() 15 | 16 | 17 | validacao = Validacao() 18 | validacao.process('carne') -------------------------------------------------------------------------------- /adapter/src/routes.py: -------------------------------------------------------------------------------- 1 | from .controller import write_in_database 2 | from .helper import Adapter 3 | 4 | def route1(message): 5 | processo = Adapter(Code()) 6 | processo.handle(message) 7 | 8 | 9 | 10 | class Code(): 11 | 12 | def handle (self, message): 13 | token = message['header']['token'] 14 | 15 | if token: 16 | print('Autentificando o Token') 17 | write_in_database( 18 | message['body']['name'], 19 | message['body']['message'] 20 | ) 21 | -------------------------------------------------------------------------------- /command/commands/button_command.py: -------------------------------------------------------------------------------- 1 | from .interface import CommandInterface 2 | 3 | class ButtonCommand(CommandInterface): 4 | 5 | def __init__(self, receptor: any, information: any) -> None: 6 | self.__receptor = receptor 7 | self.__message = self.__format_information(information) 8 | 9 | def __format_information(self, information: any) -> any: 10 | ''' header, body, token.. ''' 11 | return information 12 | 13 | def execute(self) -> None: 14 | self.__receptor.process_information(self.__message) -------------------------------------------------------------------------------- /observer/src/alarme.py: -------------------------------------------------------------------------------- 1 | from typing import Type 2 | from .interfaces import Observador 3 | 4 | class Alarme: 5 | 6 | def __init__(self): 7 | self.beep = False 8 | self.dorminhocos = [] 9 | 10 | def addPessoa(self, pessoa: Type[Observador]): 11 | self.dorminhocos.append(pessoa) 12 | 13 | def estado_alarme(self): 14 | return self.beep 15 | 16 | def tocar(self): 17 | self.beep = True 18 | for pessoa in self.dorminhocos: 19 | pessoa.update() 20 | 21 | self.dorminhocos = [] 22 | -------------------------------------------------------------------------------- /adapter/src/helper/adapter.py: -------------------------------------------------------------------------------- 1 | class Adapter: 2 | 3 | def __init__(self, process): 4 | self.process = process 5 | 6 | def handle(self, request): 7 | message = { 8 | "method": request["HTTP_method"], 9 | "header": { 10 | "token": request["HTTP_header"][0][1], 11 | "origin": request["HTTP_header"][1][1] 12 | }, 13 | "body": { 14 | "name": request["HTTP_body"][0][1], 15 | "message": request["HTTP_body"][1][1] 16 | } 17 | } 18 | 19 | response = self.process.handle(message) 20 | return response 21 | -------------------------------------------------------------------------------- /facade/models/repository_facade.py: -------------------------------------------------------------------------------- 1 | from .delete import Delete 2 | from .insert import Insert 3 | from .select import Select 4 | 5 | class Repository: 6 | 7 | def __init__(self): 8 | self.delete = Delete() 9 | self.insert = Insert() 10 | self.select = Select() 11 | 12 | def select_one(self): 13 | return self.select.select_single_element() 14 | 15 | def select_many(self): 16 | return self.select.select_many_elements() 17 | 18 | def insert_one(self): 19 | self.insert.insert_single_element() 20 | 21 | def insert_many(self): 22 | self.insert.select_many_elements() 23 | 24 | def delete_one(self): 25 | self.delete.delete_single_element() -------------------------------------------------------------------------------- /template-method/run.py: -------------------------------------------------------------------------------- 1 | from template import AlgorithimTemplate 2 | 3 | class CSV_Processor(AlgorithimTemplate): 4 | def insert_value_in_doc(self, formatted_data_with_id): 5 | print('Connecting from CSV file') 6 | print(formatted_data_with_id) 7 | print('Saving data') 8 | 9 | class DB_Processor(AlgorithimTemplate): 10 | def insert_value_in_doc(self, formatted_data_with_id): 11 | print('Connecting from Mysql DB....') 12 | print(formatted_data_with_id) 13 | print('Saving data') 14 | 15 | 16 | 17 | data1 = ['Regis', 'do Python', 'Algum Lugar!'] 18 | 19 | csvProcessor = CSV_Processor() 20 | csvProcessor.insert_data(data1) 21 | 22 | dbProcessor = DB_Processor() 23 | dbProcessor.insert_data(data1) 24 | -------------------------------------------------------------------------------- /template-method/template.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | from abc import ABC, abstractmethod 3 | 4 | class AlgorithimTemplate(ABC): 5 | def insert_data(self, data): 6 | formatted_data = self.__format_data(data) 7 | formatted_data_with_id = self.__insert_id(formatted_data) 8 | self.insert_value_in_doc(formatted_data_with_id) 9 | 10 | def __format_data(self, data): 11 | formatted_data = { 12 | "nome": data[0], 13 | "sobrenome": data[1], 14 | "cidade": data[2] 15 | } 16 | return formatted_data 17 | 18 | def __insert_id(self, formatted_data): 19 | formatted_data["id"] = randint(0, 1000000) 20 | return formatted_data 21 | 22 | @abstractmethod 23 | def insert_value_in_doc(self, formatted_data_with_id): 24 | pass --------------------------------------------------------------------------------