1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| public abstract class DimensionnedValue
{
protected double m_value;
private readonly double m_coefficient;
private readonly int m_massDimension;
private readonly int m_timeDimension;
private readonly int m_lengthDimension;
protected Dimensonnedalue() { }
protected DimensionnedValue(double value, double coefficient, int massDimension, int timeDimension, int lengthDimension) { ... }
public Value { get { return m_value; } }
public bool IsDistance { get { return m_lengthDimension == 1 && m_massDimension == 0 && m_timeDimension == 0; } }
protected double ConvertFrom(DimensionnedValue other)
{
// Vérifier que les massDimension, lengthDimension, etc... Sont bien les mêmes pour this et other.
// Car on peut seulement convertir une vitesse en vitesse, pas une vitesse en distance.
AssertDimensionsMatchWith(other);
return m_coefficient * other.m_value / other.m_coefficient;
}
public static DimensionnedValue operator *(DimensionnedValue x, DimensionedValue y)
{
return new DimensionnedValue(
x.m_value * y.m_value,
x.m_coefficient * y.m_coefficient,
x.m_massDimension * y.m_massDimension,
...);
}
} |