I have a question about naming multiple classes that share similar functionality. I am working on a scientific API and have the following classes/interfaces:
public interface IRange<T>{
T Minimum {get;}
T Maximum {get;}
// A few other methods that aren't important
}
public class Range<T> : IRange<T> where T: IComparable<T> {
public T Minimum {get; protected set;}
public T Maximum {get; protected set;}
public Range(T minimum, T maximum) {
Minimum = minimum;
Maximum = maximum;
}
}
For my API, I work with double
ranges a lot (i.e., Range<double>
), so I made an another class called MassRange
. This class also has a few new constructors and properties shown below:
public class MassRange : Range<double>, IRange<double> {
public double Width { get { return Maximum - Minimum;} }
public double Mean { get { return (Maximum + Minimum) / 2.0;} }
public MassRange(double mean, MassTolerance width) {
Minimum = mean - width.Value; // pseudo-code
Maximum = mean + width.Value;
}
}
Conceptually, I also have another type of Range<double>
called a MzRange
, that shares all the same structure and functionality as MassRange
but I want to keep separate in the API. They act exactly the same and store the same types of data, but in terms of the science, they are different and distinct.
So I considered renaming the MassRange
class to a more generic name of DoubleRange
and then have both MassRange : DoubleRange
and MzRange : DoubleRange
designed like so:
public MzRange : DoubleRange, IRange<double> {}
public MassRange : DoubleRange, IRange<double> {}
But I don't really care for the name DoubleRange
, and would rather not expose it publicly through my API. Is exposing two distinct types with the same functionality even appropriate? Should I just come up with a better name for DoubleRange
and forgo MzRange
and MassRange
? Can I make DoubleRange
internal or something so that it is not exposed through the API but can still be used?
This seems to be a case for Extension Properties but I know they don't currently exist.