Suppose that I have multiple instances
I3, etc. of a set of classes
C2, etc. Suppose that these classes are all inheriting from a super-class
Suppose that there is an operation
O(a, b) that takes two instances of
S and see if they are compatible (compatible in some since.) In order to check for compatibility, however, O has to know the type of
C2, ...) and the operation can only be done once the types are known.
The basic way to implement
O would be to write if statements everywhere to check the types, and then run the operation. This is not ideal because there are many cases to cover and because it is not extendable.
Is there a pattern associated with these sorts of problems? Away to write an extendable operation that is based on types?