downcasting problem
Diez B. Roggisch
deets at web.de
Mon Oct 25 16:26:17 EDT 2010
More information about the Python-list mailing list
Mon Oct 25 16:26:17 EDT 2010
- Previous message (by thread): downcasting problem
- Next message (by thread): downcasting problem
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Nikola Skoric <nick at fly.srk.fer.hr> writes: > Hi everybody, > > I need to downcast an object, and I've read repeatedly that if you > need to downcast, you did something wrong in the design phase. So, > instead of asking how do you downcast in python, let me explain my > situation. > > I have a 2-pass parser. 1st pass ends up with a bunch of superclass > object, and 2nd pass is supposed to downcast those to one of > subclasses so I can work with them. This is usually called a 'reducer' in parsing, and it's purpose is to rewrite the parsing result to something new. It's usually implemented using a visitor-pattern. In your case, it should be rather straightforward, by simply iterating over the objects and creating new, more specialized types depending on what you actually need. So you don't need to delegate anything. Diez
- Previous message (by thread): downcasting problem
- Next message (by thread): downcasting problem
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list