I’d like to design a class that holds comparison results about to objects.
Given I have a class
Thing and that
Thing has a bunch of properties. Now I have an engine that compares
Thing instances (held in a collection) to one another. Comparisons are actually Types deriving from a
Comparison base class and can be fairly complex (e.g. ColorComparison). The actual result is not of importance, only that the comparison results in a match. So if comparing two
Thing instances succeeds the comparison will be stored in a
Match class, along with information about the applied comparison. So a
Match class might have the properties
I later need to store the
Match class instances in a HashSet for fast lookup. What identifies a
Match is the combination of ThingA and ThingB. In a perfect world the
Match class could provide the same Hash for ThingA = x and ThingB = y vs. ThingA = y and ThingB = x. It might be later needed that not only one Comparison is stored within a Match but several different.
Some additional implementation notes:
- Once a
Matchclass has been instanciated, both ThingA and ThingB are immutable
- The Things inside a
Matchcannot be manipulated (e.g. I cannot store the relationship information inside them)
My question is, how to I design the
Match class in a way that when the HashSet is searched for the x and y combination of
Things it also finds the y and x combination.