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
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.
- create a immutable class ScaleValueDefinition with value and definition as properties and use it in a list.
- use a dictionary.
- 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