For my example, I have a Person class with an arbitrary number of associated Addresses associated with it. So there will be an Addresses collection as a member of the Person class.
In many applications which use the Person class, we will just want to retrieve the "Default" Address object. There are a few design questions regarding the implementation:
- On each Address record in the DB, I could have a flag to set whether it is default for the collection. Alternatively, I could have different types of addresses (Home, Billing, Shipping, etc...) and set up rules to say that if a person has a Home address record, use it as the default. If not, then use Shipping, etc...
As for the interface used to retrieve the default Address, there are many ways we could do it, and I'd like to know what feels best to some of the SO folks.
Address a1 = myPerson.DefaultAddress; Address a1 = myPerson.Addresses["Default"]; Address a1 = myPerson.Addresses.Default;
It's probably good advice to say, "It depends on your application." Let me preempt that by saying we're building some foundational classes for all of our new development. So I can't necessarily just look at this first app we're building as the final word on class design.