Building a pretrigger / posttrigger framework class

rh0dium steven.klass at gmail.com
Mon Jan 21 15:03:32 EST 2008


Hi all,

I am thinking about a class which can automatically determine the
order which it is run.  I would like to implement a super class which
has a run() method and a pretrigger() method.  The purpose of the
pretrigger method is to state what classes need to be run before this
class.run() method is executed.

So for example:

class superclass(object):
    def run(self):
        """Method which will get overriden"""
    def pretrigger(self):
        """Method which will get overriden and determine the order"""

class subclassA(superclass):
    def run(self):
        print "I am subclass A"
    def pretrigger(self):
        return [subclassB(),]

class subclassB(superclass):
    def run(self):
        print "I am subclass B"
    def pretrigger(self): None
        return [subclassC(), ]

class subclassC(superclass):
    def run(self):
        print "I am subclass C"
    def pretrigger(self): None
        return None

Now what I am looking for is some logic which can look at this and
draw the following conclusion.
- In order to run subclassA, I first need to run subclassB.  In order
to run subclassB I need to run subclassC.  So the order to run this
would be subclassC, subclassB, then subclassA.
I would also like some information on is this a good approach to using
a superclass or not?

Any and all comments are welcome.  Thanks!!




More information about the Python-list mailing list