"casting" Python objects

Donn Cave donn at drizzle.com
Thu May 23 01:17:29 EDT 2002


Quoth David Bolen <db3l at fitlinxx.com>:
...
| The right approach is to create the appropriate subclass of
| jabber.Message before putting it into the queue.  Your retrieval code
| won't have to worry which subclass it is, since they'll all have the
| Handler function and will be dispatched appropriately.  So from the
| info in your original post, it sounds like your connection object is
| the one that should be determining what sort of object instance to
| create (e.g., FooMsg) and creating an instance of that to post to the
| queue rather than jabber.Message.

Or, perhaps the right approach doesn't involve inheritance at all!

The object with the Handler method probably shouldn't _be_ a Message,
it should just _have_ one.  If you have to subclass Message just to
get useful access to its contents, it's seriously broken;  if you
subclass it for that reason when you don't need to, you're asking
for more trouble than you already have.

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list