R
RedLars
Hi,
Appreciate some input on a small design issue. Need to represent a
version in an application that come in various formats (1.2.3 or 'a')
and number of octets (1.2 or 1.2.3.4.5).
Considering using an interface as shown below with two implementations
(for now). Lets for simplicity call them VersionNumber and
VersionCharacter.
interface IVersion : IComparable<IVersion>
{
}
Comparing two instances of the same implementation is fairly
straightforward (i.e. compare VersionNumber with VersionNumber).
However comparing a VersionNumber instance with a VersionCharacter is
more difficult IMHO. How do I specify which is greater and how do I
model that? Obviously a third implementation could also appear at some
point. Should such a decision be dealt with internally in each class,
for instance VersionNumber is always greater than another IVersion
type. Then you can get inconsistencies if VersionCharacter has the
opposite rule. So I was thinking about having a central method for
this specific sort of decision but must admit I'm uncertain at this
point. Any other way of solving the issue would be interesting.
Hope I explained the problem properly. If you see any other problems
with the design I’m all ears.
The goal is to have a flexible and maintainable implementation (maybe
asking too much).
Appreciate some input on a small design issue. Need to represent a
version in an application that come in various formats (1.2.3 or 'a')
and number of octets (1.2 or 1.2.3.4.5).
Considering using an interface as shown below with two implementations
(for now). Lets for simplicity call them VersionNumber and
VersionCharacter.
interface IVersion : IComparable<IVersion>
{
}
Comparing two instances of the same implementation is fairly
straightforward (i.e. compare VersionNumber with VersionNumber).
However comparing a VersionNumber instance with a VersionCharacter is
more difficult IMHO. How do I specify which is greater and how do I
model that? Obviously a third implementation could also appear at some
point. Should such a decision be dealt with internally in each class,
for instance VersionNumber is always greater than another IVersion
type. Then you can get inconsistencies if VersionCharacter has the
opposite rule. So I was thinking about having a central method for
this specific sort of decision but must admit I'm uncertain at this
point. Any other way of solving the issue would be interesting.
Hope I explained the problem properly. If you see any other problems
with the design I’m all ears.
The goal is to have a flexible and maintainable implementation (maybe
asking too much).