Skip to content

Instantly share code, notes, and snippets.

@cassioeskelsen
Last active November 6, 2021 23:40
Show Gist options
  • Save cassioeskelsen/4f188d504a41afaa568b78818baa1b77 to your computer and use it in GitHub Desktop.
Save cassioeskelsen/4f188d504a41afaa568b78818baa1b77 to your computer and use it in GitHub Desktop.
from abc import abstractmethod
from typing import List, Protocol
from dataclasses import dataclass
@dataclass
class Customer:
id: int
name: str
class CustomerRepository(Protocol):
@abstractmethod
def get_customers(self) -> List[Customer]:
""" retorna uma lista de clientes"""
@abstractmethod
def get_special_customers(self) -> List[Customer]:
""" retorna uma lista de clientes especiais"""
class MongoCustomerRepository:
def get_customers(self) -> List[Customer]:
print("mongo repository")
return [Customer(1, 'xpto'), Customer(2, 'foo bar')]
def ExemploService(cr: CustomerRepository):
print(*cr.get_customers(), sep='\n')
if __name__ == '__main__':
mc = MongoCustomerRepository()
ExemploService(mc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment