[Edu-sig] Design Patterns

André Roberge andre.roberge at gmail.com
Thu Aug 25 18:00:22 CEST 2005


Disclaimer: I haven't followed this thread as closely as I should.

Picking up on a few words from the discussion
(namely "triangle" and "properties").

When I think of a real life triangle, I can describe it
in terms of various "properties", such as: the length of
each of its three sides, its area, the three internal
angles, its perimeter, etc.  Of course, most of these
properties are interdependent.

If I want to refer to a triangle property using the
"dot" notation, I want to write:
triangle.area
triangle.perimeter
triangle.shortest_side
triangle.longest_side
etc.

Now, imaging taking a program similar to "Paint"
and drawing a triangle.
Then change it somewhat (by flipping it, lengthening one
side, etc). [Unlike "paint", our program keeps track of
objects' nodes.]

Suppose I am lengthening one side from 100 horizontal pixels to 120
horizontal pixels (looking at the status bar where such information
is displayed).
When I change one value, others may change too.
When I change one value, I am first and foremost
interested about that particular value ... I don't
want to have to think of what other values
("properties") may need to change.

--- Now, back to computer programming

Python properties make it possible to think of all of an
object's attribute on an equal footing (given an appropriate
design for the class to which the object belong).  Without
properties, I have to distinguish between values that
can be assigned directly and those that must be computed.
Of course, a lot of work has to be done behind the scene
to keep things consistent.

Java's "recommended" way would be to use a set method
for assignment and a get method for retrieval
(with the same required work done behind the scene).

I find Python's properties much more elegant (and simpler
for the end user) than having a whole bunch of get_this()
set_that() to use.

André



More information about the Edu-sig mailing list