From: Ralph Aichinger Date: 2004-06-27T22:43:02+09:00 Subject: Newbie: How to model this? Please be kind, this is probably a completely dumb newbie question, but I just finished reading the Thomas/Hunt book and have basically no previous experience with truely object-oriented programming: How do I do the following in a elegant fashion? I want to work with an object describing geographical coordinates as you can read them from a GPS. At least I need the longitude, latitude and height of the point as an instance variable, as far as I can see. So far so good: class Location def initialize(lon,lat,hgt) @lon = lon @lat = lat @hgt = hgt end end Latitude and longitude are basically angles, which can be described in degrees, minutes and seconds or decimal degrees, and a number of other formats. I want methods like myPoint.dmsdegrees giving just the degrees part of myPoint in degree, minute, second format. These should be "virtual attributes" if I understand Thomas/Hunt right. How can I define this in the most elegant fashion? I cannot let Location inherit this from a base class "Angle" with all these conversion methods, can I, because a Location is not a Angle, at least not just a Angle. Of course I could just code these conversion methods twice (once for lat, once for lon) for each conversion in the body of the class "Location". However I think there *must* be a better method than this copy&paste techniqe. TIA /ralph