Class or Dictionary

Posted by user2038134 on Programmers See other posts from Programmers or by user2038134
Published on 2013-10-08T15:04:16Z Indexed on 2013/10/18 4:11 UTC
Read the original article Hit count: 211

Filed under:
|
|

I want to create a immutable Scale class in C#.

public sealed class Scale
{
    string _Name;
    string _Description;
    SomeOrderedCollection _ScaleValueDefinitions;
    Unit _Unit

    // properties
    ....
    // methods
    ContainsValue(double value)
    ....

    // constructors
    // all parameters except scalevaluedefinitions are optional
    // for a Scale to be useful atleast 1 ScaleValueDefinition should exist
    public Scale(string name, string description, SomeOrderedCollection scaleValueDefinitions, unit)
    { /* initialize */}
}

so first a ScaleValueDefinition should be represented by to values:

  • Value (double)
  • Definition (string)

these values are known before the Scale class is created and should be unique. so what is the best approach.

  1. create a immutable class ScaleValueDefinition with value and definition as properties and use it in a list.
  2. use a dictionary.
  3. use another way i didn't think of...

and how to implement it. for option 1. i can use params ScaleValueDefinition[] ValueDefinitions in the constructor, but how to do it for the other options?

and as last at what amount of value's (properties) should i choose one option over the other?

© Programmers or respective owner

Related posts about c#

Related posts about class