Exemple #1
0
        him.hits.append('perfore')
        return him
 
class TotoWarrior (ArmedWarrior):
    def fight(self):
        super(TotoWarrior, self).fight()
        print 'fait toto!'
 
class ArmedWarrior2 (ArmedWarrior):
    def how_feel(self):
        try:
            self.hits.index('perfore')
            print 'Damned! je suis perfore !'
        except ValueError:
          super(FooWarrior, self).how_feel()
 
factory = Factory()
 
factory.extend('Warrior', SpaceWarrior, BaseWarrior)
factory.extend('Warrior', ArmedWarrior, BaseWarrior)
 
factory.extend('Warrior', TotoWarrior, ArmedWarrior)
factory.extend('Warrior', ArmedWarrior2, ArmedWarrior)
 
some_bug_hited = factory.get_class('Warrior')()
 
warrior = factory.get_class('Warrior')()
warrior.hit(some_bug_hited)

print 'and hited bug say:'
some_bug_hited.how_feel()
Exemple #2
0
from factory import Factory
import spaceobjects
import armedobjects

factory = Factory()

warrior = factory.get_class('Warrior')()
warrior.fight()