Python Patterns

Jacek Generowicz jacek.generowicz at
Wed Oct 6 10:11:56 CEST 2004

aleaxit at (Alex Martelli) writes:

> Irmen de Jong <irmen at> wrote:

> > This "state" pattern needs a clumsy internal state object in C++
> > but in Python we can just change the object's class directly,
> > which is a much more direct implementation of what the pattern
> > tries to achieve :-)
> Right, good point.  In C++ you can do something closer with the Strategy
> pattern -- still one level of indirectness, but a consistent set of
> methods (embodied in the one strategy object) commuted as a whole.
> Assigning __class__ IS of course more direct, yes;-).

Isn't Strategy more like rebinding the methods of a class, rather than
rebinding the .__class__ of an instance ?

More information about the Python-list mailing list