Last active
November 6, 2021 23:40
-
-
Save cassioeskelsen/4f188d504a41afaa568b78818baa1b77 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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