Kaspar Schiess wrote: >> 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? > > If there is one proximity function per valid pair, storing that > function/method in a specialized class is not a bad idea. Most likely > though you'd have some kind of default behavior for the pair proximity > and then some special cases depending on one, the other or both of the > elements of the pair. > > I guess a good class design would try to capture the common cases first, > specializing only where needed. In the general case you might have > something like > > class ProximityTuple > attr_reader :base, :reference > > # setup .. > > def proximity > if base.respond_to? :proximity_to > return base.proximity_to(reference) > end > > if reference.respond_to? :proximity_to > return reference.proximity_to(base) > end > > # default behaviour > end > end > > class SpecializedTuple < ProximityTuple > # ... > > def proximity > # special implementation > end > end > > > This would be customizable by either letting the default do the work, or > let one of the participants do the work, or the specialized tuple. > > If you would care to more closely describe the kind of objects you're > handling and the function(s) involved this might get simplified (again) > considerably. This is the best I can come up with in the abstract case > ;) > > regards, > kaspar Kaspar, I would be happy to share more details about what I am doing with you and with the community but it is a little to early for that, not because I have something to hide, but because I don't have much to show. So right now I am more interested in general approcahes and best practices, that will help me decide about some conceptual issues. In this context your answer is very helpful. Thanks, Oren -- Posted via http://www.ruby-forum.com/.