[Tutor] Re: Factory classes (etc)

Patrick K. O'Brien pobrien@orbtech.com
Wed, 4 Sep 2002 08:45:40 -0500


[Arthur]
>
> Quite glad the discussion came up.
>
> Rightly or wrongly, I am convinced that the standard Python approaches to
> class constructors don't quite work in my situation and I need to
> go further.
>
> But it seems I can leave my 40 odd classes intact, and create
> "consolidating"
> Factory classes with which the user interacts, and which will
> (hopefully, eventually) create the appropriate instances based on argument
> signature.
>
> Whereas Factory classes do not directly solve my problem, which I am
> calling a mothod overloading issue, I think it does point to a
> significantly
> better
> approach than the path down which I had been going.

Take a look at Bruce Eckel's Thinking in Python book
(http://www.mindview.net/Books/TIPython). Chapter 11 has a couple of nice
examples of Multiple Dispatching. In particular, the second example uses a
dictionary to hold tuples of class combinations that map to certain values.
You should be able to do something like this combined with a Factory pattern
to determine what class to instantiate based on the class/type of your
arguments.

--
Patrick K. O'Brien
Orbtech
-----------------------------------------------
"Your source for Python programming expertise."
-----------------------------------------------
Web:  http://www.orbtech.com/web/pobrien/
Blog: http://www.orbtech.com/blog/pobrien/
Wiki: http://www.orbtech.com/wiki/PatrickOBrien
-----------------------------------------------