Assume we have a Customer class which has a complex property called Address. Something like this:
public class Customer
{
public string Name { get; set; }
public Address { get; set; }
}
I need to implement Data Mapper pattern to p开发者_如何学JAVAersist Customer objects to the database. Should I have something like CustomerDataMapper that persists the Customer AND the Address or 2 different Data Mappers: CustomerDataMapper and AddressDataMapper?
I'd like to know your thoughts on this.
Cheers,
Mosh
If you want to map by hand, I would suggest having two mappers, with CustomerDataMapper
delegating to AddressDataMapper
for that property. This allows you to test the mappings separately and potentially reused the address mapper elsewhere.
An ORM like LINQ to SQL or NHibernate could take care of this for you.
精彩评论