1 - Progetta le mie entità, cioè (in python):
class Account:
def __init__(name, author):
self.name = name
self.email = email
2 - Progetta i miei repository: (come interfaccia)
class AccountRepository:
def add(self, account):
""" @type account Account """
pass
def find_by_name(self, name):
pass
def find_by_email(self, email):
pass
# remove, and others...
Ora, posso andare in due modi:
A: Progetta e implementa i miei servizi di dominio:
class SignUpService:
def __init__(self, account_repository):
""" @type account_repository AccountRepository """
self._account_repository = account_repository
def create_account(self, username, email):
account = Account(username, email)
self._account_repository.add(account)
# other methods that uses the account_repository
B: Implementa le mie strategie di repository:
class MongodbAccountRepository(AccountRepository):
def __init__(self, mongodb_database):
self._mongodb_database = mongodb_database
def add(self, account):
account_data = account.__dict__
self._mongodb_database.accounts.insert(account_data)
# and the other methods
Qual è l'ordine corretto? e perché? 1, 2, A, B o 1, 2, B, A?
Grazie mille!