Design Question - primary member of collection.

Design Question - primary member of collection.

Old forum URL: forums.lhotka.net/forums/t/471.aspx


skagen00 posted on Monday, June 26, 2006

I did some searching but couldn't seem to find a thread to address this question.

Here is my example - basically names that may be associated with an individual.

An individual always has a name (a primary name).

An individual may also have "alternate names" or aliases.

There will be a child class that represents an individual's name. It may have the name parts plus a well defined set of derived name builds (which can be overwritten by the user).

Two choices that I can think of when it comes to designing the classes:

1) Individual has a PrimaryName (simple child) plus a collection of AlternativeNames.

               Individual --> IndividualName (PrimaryName) and

               Individual --> IndividualNameCollection --> IndividualName (AlternativeNames)

2) Individual has a collection of Names, one of which is marked as primary.

               Individual --> IndividualNameCollection --> IndividualName

               When considering this, it seemed like it might be a little tricky handling the primary. Does the Individual contain a "primary name" reference to the primary in the collection, etc.

One assumption to make as well is that 90%+ of individuals will likely only have one name ever entered, and probably less than 1% would have more than one alternative name.  

I am leaning towards option one, and I'm hoping someone can educate me on whether or not that is the right choice. I think it will be easier to conceptualize and easier to work with when binding to the UI.

I could see other collections that contain primaries to perhaps take a different approach, but my only concern at the moment is this one with names.  Obviously, this would be normalized when it came to the DB.

Thanks for any input.

RockfordLhotka replied on Monday, June 26, 2006

For data binding, the idea would be to flatten the primary name directly into Individual, so it doesn't appear as a child object at all. At least that's the simplest way to get data binding to work.

Inside Individual you'd do the collection idea, with one of the items being the primary. The concept of primary belongs to the collection, not to the children. So Individual's Name property would be something like this:

Public Property Name() As String
  Get
    Return mNames.PrimaryName.FullName
  End Get
  Set
    mNames.PrimaryName.FullName = value
  End Set
End Property

 

Copyright (c) Marimer LLC