OO approach to decision sequence?

George Sakkis gsakkis at rutgers.edu
Sat Jun 18 15:10:25 CEST 2005

"Chinook" wrote:

> I understand what you are saying.  The point I'm messing up my head with
> though, is when the entity (tree node in my case or variable record content
> deconstructing in the aspect example I noted) is not an instance of a class
> already - it is obtained from an external source and only decipherable by its
> content.
> In practical terms that leaves me with some decision sequence regardless and
> I was wondering (from what Chris Smith said) how that might be done in OOP.
> The whole problem may be that I'm reading too much into what Chris said :~)
> I will dig back through the Tutor archives as you suggested.

What you are looking for is what is called the 'factory method pattern'
(http://en.wikipedia.org/wiki/Factory_method_pattern) and it's one of
the cases where OOP doesn't eliminate the if/elif/elif (or switch in
C++/Java). That's ok though because, as you noticed, at some point you
have to take a decision. What's important is the "once and only once"
principle, that is all the decision logic is encapsulated in a single
method (or in python in a single function) instead of being replicated
every time you want to use an existing Node.


More information about the Python-list mailing list