object - Python - a way to instantiate class, without assigning it? -


i'm working on module i'm hoping dynamic, in can add features relatively easily.

the basic idea have class, criticbase, handles criticisms deployment. critics class has inherited criticbase.

pseudo example:

class criticbase(object) {      def self.execute():          critic in self.__subclasses__: critic.run() }  class databasecritic(criticbase) { def run( //things ) } class diskspacecritic(criticbase) { def run( //things ) } etc...  def dowork():     controller = criticbase()     = databasecritic()     b = diskspacecritic()     ...     controller.execute() 

i hope kind of makes sense. idea have framework that's straightforward other devs add to. need define subclass of criticbase, , else handled critic framework.

however, it's pretty ugly me assign these classes that's never going used. there such thing lingering objects in python? away assignment, , still have reference instantiated class base class? or have have assigned something, otherwise garbage collected?

my understanding don't want other devs instantiate sub-classes. actually, don't need that, long method run() class method:

# framework provides base class class criticbase(object):     @classmethod     def execute(cls):          critic_class in cls.__subclasses__():              critic_class.run()  # devs need provide definition of subclass class databasecritic(criticbase):     @classmethod     def run(cls):        # specific database  class diskspacecritic(criticbase):     @classmethod     def run(cls):        # specific disk space  # base class work def dowork():     criticbase.execute() 

with approach, use python's inheritance machinery collect subclasses list, , code free useless instantiations.


Comments