views:

33

answers:

1

If you have one Contact, with a 1:* relationship with Addresses, and possibly one or more other tables used to hold the persisted value objects -- how many repositories should there be?

Should there be just one ContactRepository with one public method (GetContact(), that internally calls a private method (GetAddresses)) that returns a fully hydrated entity (Contact+Addreses)?

Or should there be two Repositories -- one For Contacts, one for Addresses with the COntactsRepository calling the AddressRepository?

Or other?

Thank you!

A: 

Can anything other than a Contact have an Address?

If not, I'd probably think about having just a ContactRepository.

If there also exist entities like Orders, Events, etc, that have Addresses, I'd think about a separate AddressRepository.

Your Mulberry road/drive example implies that you only want one address record for "123 Mulberry Rd", no matter how many Contacts have that address, that might well create more impetus to do an AddressRepository.

timdev
Tim. Thanks very much. I think you hit it on the nail that it is a matter of need more than anything.I think the guiding decising is what is needed from a Domain point of view: Currently the Domain is dealing with Contact entities only. Up till the point that the DOMAIN starts to talk in Addresses as well (as Entity objects in their own right, and not Value Types), it remains just needing at best its own AddressTable class (for SOP reasons) without needing to be exposed as a full blown Repository. Thanks.
Ciel