Re: [Edu-sig] Uniform Access Principle confusion

-----Original Message----- From: Kirby Urner [mailto:urnerk@qwest.net]
class Angle (object):
def __init__(self, thevalue): self.value = float(thevalue)
@property def degrees(self): return self.value
@property def radians(self): return math.radians(self.value)
class Triangle (object):
def __init__(self, A=30, B=60, C=90): self.A = Angle(A) self.B = Angle(B) self.C = Angle(C)
Works for me. And I think pedagogically valuable as an approach. For an (embarrassingly) long time I had complicated my class hierarchies by not seeing the simple possibilities of creating classes to act as attributes of more far-reaching classes. Its simple and obvious - once it's simple and obvious. Downsides, warnings? Art

Its simple and obvious - once it's simple and obvious.
Downsides, warnings?
Art
So far we're looking at pretty straightforward composition of objects (less an inheritance pattern), i.e. angle objects composed in a triangle. However, it could easily needlessly complexify, the bane of good style. Keeping it simple is actually harder than giving in to tempting clevernesses. There's nothing here yet to stop an uninitiated user from trying to start a new triangle with radian inputs. I should post a guard, or at least better document the API (perhaps using __doc__ strings). Also, AAA (angle-angle-angle) isn't usually considered a sufficient criterion for congruence (in topology it might), as no edge size has been specified (i.e. only similarity has been established). So the above Triangle class more defines an equivalence class than a template for any one triangle. That may lead to confusion down the road. That's all I can think of at the moment. When it comes to finding weaknesses, that's generally a drawn-out process. Thanks for asking though -- you helped me get thoughtful. Kirby
participants (2)
-
Arthur
-
Kirby Urner