I need a List of items with sharable behavior.
Example:
Person class
has List<PhoneNumber>
where only one PhoneNumber is bool IsPrimary
same for other items
has List<EmailAddress>
has List<Address>
Imagine each item (PhoneNumber, EmailAddress, Address) share the same interface ICanBePrimary which contains the requirement of one property bool IsPrimary and when in a List<ICanBePrimary> only one item in the list can have a true value for IsPrimary.
The cleanest approach would be to hide a list behind a class that lets you enumerate over the content, and provides additional methods for identifying the primary item:
An even cleaner implementation would encapsulate the list inside your
AddressListclass, and expose only the methods that you want exposed: