[Tutor] Re: Factory classes (etc)

Magnus Lycka magnus@thinkware.se
Thu, 05 Sep 2002 16:19:22 +0200


At 10:20 2002-09-05 +0200, Scot W. Stevenson wrote:
>Ah, now I understand. Just as an aside, if I were to really programm
>something like this (which is certainly the best way to understand the
>principle), would I want to use a if-elif-else construct like above, or
>rather a dictionary such as:
>
>shapes =3D {0: Circle, 2: Line, 3: Triangle, [...]}
>
>and then do a
>
>shapes[corners](x, y, size, angle)
>
>which would assume that Circle doesn't go balistic if it is suddenly handed
>an angle. Again, I'm glad you did it this way here, because it is easier
>to understand.

Well, if it was easier for you to understand with the if statement,
then that is probably a better way of coding it... The dictionary
construct is not unknown among python programmers, but it's probably
more likely to confuse, and you need to handle both Circle (which in
my imagined implementation didn't take angle) and Polygons that want
the number of sides as a parameter.

If it had been 20 choices or so, I might have preferred the dictionary
approach since it's less verbose.

>Does anybody actually _use_ SmallTalk for production code, or is it one of
>those teaching languages that revolutionized various concepts but never
>made it in the market (sort of like Multics [sp] vs. Unix, or the League
>of Nations vs. the United Nations, or for that matter, "Buffy" the Film
>vs. "Buffy" the TV series)?

Certainly, although it seems some of them are forced over to Java.
Since GemStone, the favourite database of SmallTalkers is now ported
to Java, they seem to be able to live with that.
Check out Portland again: http://www.c2.com/cgi/wiki?search=3Dsmalltalk
Perhaps you should look at=
 http://www.c2.com/cgi/wiki?SmalltalkInsteadOfPython

>Are there any common patterns that are missing by today's standards? I'm
>thinking about the Borg "non-pattern" described in the "Python Cookbook" -
>I can't believe that seven years later, the GoF is still state of the
>art...

GoF might be state of art, or at least still considered a good first
book about patterns, but it's certainly not intending to be a catalog
of _all_ software design patterns. I'm sure the authors had no such
ambition. There are a few more books here:

http://c2.com/cgi/wiki?PatternRelatedBookList

I have some stuff about Patterns and Python here:
http://www.thinkware.se/cgi-bin/thinki.cgi/PythonPatterns
http://www.thinkware.se/cgi-bin/thinki.cgi/PatternCatalog


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se