I’m working on a project which has a rich domain-model.
Some of my classes have collections of other types, and those other types have a property that refers back to their ‘owner’. This sounds maybe a bit cryptic, so a code example would help:
public class Product { private IList<ProductPrice> _prices = new List<ProductPrice>(); public void AddPrice( ProductPrice price ) { price.Product = this; _prices.Add (price); } } public class ProductPrice { public DateTime ValidationDate {get; set;} public Decimal Price {get; set;} public Product Product {get; set;} }
The question is: what name do you prefer for the ‘Product’ property of the ProductPrice class ?
Would you name it: – Product (like it is now) – Owner – BelongsTo – something else ?
Product – there’s no ambiguity and the naming is consistent – Product stays Product everywhere.
If accessing the property from outside, I’d prefer having this:
than this: