I\'m implementing value types which represents a distance (or length). There\'s an enum that represents the different units of measure, eg:
public enum Distance
Do you really need an enum
here? Maybe, a simple value object will do?
public class Distance
{
private readonly decimal millimeters;
public decimal Meters
{
get { return millimeters * 0.001m; }
}
private Distance(decimal millimeters)
{
this.millimeters = millimeters;
}
public static Distance Yards(decimal yards)
{
return new Distance(yards * 914.4m);
}
}
With extension methods you and properly defined operators can get very Ruby-like syntax:
var theWholeNineYards = 9.Yards() + 34.Inches();