[Edu-sig] Uniform Access Principle confusion
Arthur
ajsiegel at optonline.net
Fri Oct 14 04:30:01 CEST 2005
> -----Original Message-----
> From: Kirby Urner [mailto:urnerk at 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
More information about the Edu-sig
mailing list