O
Oren Shani
Hi All,
First of all I think you should know that I am quite new to Ruby. I have
many years of experience with other programming languages tough, and I
must say that Ruby is really great!
And now to my question - I am working on something that makes use of
proximity functions, which are functions that take two objects ("base"
and "reference") and return a real number in the range of [0..1], based
on how "the same" the objects are (1 means identical, 0 means completley
different and a fractions means a certain degree of proximity). The
objects do not have to be of the same type. For example, a number can be
compared to a range, a string can be compared to a regular expression,
etc, but of course, not all combinations are possible.
Now the point is that the process for calculating the proximity very
much depends on the types of objects compared, so it is actually a
method of the objects-pair, so the most obvious thing I can do is define
a class for each valid pair combination, but that does not seem to me as
very elegant. Another thing I can do is to define the proximity function
as a method of each object and somehow re-define the needed sub-methods
per each class of valid reference-object, but that still looks a little
messy, I think.
So does anyone have any other ideas for doing this kind of object-pairs
dependent coding, is ther some kind of best-practice for this situation?
Your thoughts and ideas are much appreciated!
Oren
First of all I think you should know that I am quite new to Ruby. I have
many years of experience with other programming languages tough, and I
must say that Ruby is really great!
And now to my question - I am working on something that makes use of
proximity functions, which are functions that take two objects ("base"
and "reference") and return a real number in the range of [0..1], based
on how "the same" the objects are (1 means identical, 0 means completley
different and a fractions means a certain degree of proximity). The
objects do not have to be of the same type. For example, a number can be
compared to a range, a string can be compared to a regular expression,
etc, but of course, not all combinations are possible.
Now the point is that the process for calculating the proximity very
much depends on the types of objects compared, so it is actually a
method of the objects-pair, so the most obvious thing I can do is define
a class for each valid pair combination, but that does not seem to me as
very elegant. Another thing I can do is to define the proximity function
as a method of each object and somehow re-define the needed sub-methods
per each class of valid reference-object, but that still looks a little
messy, I think.
So does anyone have any other ideas for doing this kind of object-pairs
dependent coding, is ther some kind of best-practice for this situation?
Your thoughts and ideas are much appreciated!
Oren