So far I've been building applications abstracting data entity operations behind the use of Repositories
. Each of them would encapsulate the domain that corresponds to their defined entity. For instance: UserRepository
would encapsulate domain logic regarding the User
entity, such as changePassword(old,new)
, createAccount(email,password
, retrieveAllFriendsForUser(id)
and such.
But there are cases where you need multiple resources to interact and abstracting that logic in a repository from another entity feels smelly. For example: buying an Item
would require you to create a Quotation
, create a Payment
, reducing the ItemQuantity
from the Inventory
and such; handling that operation in the ItemRepository
would mean it's implementation would depend on QuotationRepository
, PaymentRepository
, etc...
I've read before about the Business Facade and the Unit of Work patterns, but having just read them again they seem not to be aimed at this specific multiple resource interaction issue, but rather aimed at simplified access to chunks of code and handling atomic operations, respectively.
What's a design pattern for handling multiple resource interaction and if possible a quick example code that complements it.
PurchaseRepository
orPurchaseService