4 ms·
I can't help but feel that the powerup_type change is short-sighted. In the new code, the enumeration of powerup types happens three times, in three different
by tomku 14y ago
I can't help but feel that the powerup_type change is short-sighted. In the new code, the enumeration of powerup types happens three times, in three different places. The first is in Powerup's constructor as a tuple of strings, the second is in Powerup.render as three paths of an if/else, and the third is in GameWorld.apply_powerup as the keys to a hash of functions.
It feels wrong that GameWorld should keep track of a list of powerup types independently from instances of the Powerup class, and that Powerup instances have no knowledge of what they do. It smells suspiciously like using strings as a substitute for object types. To me, that hints that there are stronger refactorings to be found that could take advantage of polymorphism or a strategy pattern, depending on your taste for inheritance hierarchies.