Is Using Tuples in my .NET 4.0 Code a Poor Design Decision?
Posted
by Jason Webb
on Stack Overflow
See other posts from Stack Overflow
or by Jason Webb
Published on 2010-06-10T18:33:11Z
Indexed on
2010/06/11
14:52 UTC
Read the original article
Hit count: 157
With the addition of the Tuple class in .net 4, I have been trying to decide if using them in my design is a bad choice or not. The way I see it, a Tuple can be a shortcut to writing a result class (I am sure there are other uses too).
So this:
public class ResultType
{
public string StringValue { get; set; }
public int IntValue { get; set; }
}
public ResultType GetAClassedValue()
{
//..Do Some Stuff
ResultType result = new ResultType { StringValue = "A String", IntValue = 2 };
return result;
}
Is equivalent to this:
public Tuple<string, int> GetATupledValue()
{
//...Do Some stuff
Tuple<string, int> result = new Tuple<string, int>("A String", 2);
return result;
}
So setting aside the possibility that I am missing the point of Tuples, is the example with a Tuple a bad design choice? To me it seems like less clutter, but not as self documenting and clean. Meaning that with the type ResultType
, it is very clear later on what each part of the class means but you have extra code to maintain. With the Tuple<string, int>
you will need to look up and figure out what each Item
represents, but you write and maintain less code.
Any experience you have had with this choice would be greatly appreciated.
© Stack Overflow or respective owner