An abstract factory class is used to define an infrastructure for modular code. What does this mean ? Say you have a situation where you have a set of filters that you might want to apply to an image. In traditional C++ code, you would make a class or method for each filter, and would then have to hard-code the name of each of the different functions wherever you want to use them. Abstract factories provide a mechanism for having a set of such filters and calling them by name at runtime, generally with introspection. Introspection meaning a program can ask (at runtime) for a list of all of the available filters, and their parameters, documentation, etc. So, a GUI presenting the user with a list of filters would not need to modify their code at all when a new filter was added to the system. It would all happen transparently. EMAN2 uses this infrastructure for a range of different types of functions, including processors (1 image in -> 1 image out), reconstructors (many images in -> 1 higher dimension image out), projectors (1 high dimension image in -> many lower dimension images out), etc. This particular file documents the infrastructure used to make this happen. You don't really need to read this in most cases unless you want to implement an entirely new type of modular class. The EMAbstractFactory class is defined in EMAN2.py. It can be used for designing factory based python code. It is initially taken from [[http://code.activestate.com/recipes/86900/|a factory in python]], where the first two discussion points (on that page) have been duly noted and related alterations have occurred. {{{#!python >>from EMAN2 import EMAbstractFactory >>f=EMAbstractFactory() >>class A:pass >>f.register("createA",A) >>f.createA() <__main__.A instance at 01491E7C> >>> class B: ... def __init__(self, a,b=1): ... self.a=a ... self.b=b ... >>> f.register("createB",B,1,b=2) >>> f.createB() >>> b=f.createB() >>> >>> b.a 1 >>> b.b 2 >>> class C: ... def __init__(self,a,b,c=1,d=2): ... self.values = (a,b,c,d) ... >>> f.register("createC",C,1,c=3) >>> c=f.createC(2,d=4) >>> c.values (1, 2, 3, 4) >>> f.register("importSerialization",__import__,"cPickle") >>> pickle=f.importSerialization() >>> pickle >>> f.register("importSerialization",__import__,"marshal") >>> pickle=f.importSerialization() >>> pickle >>> f.unregister("importSerialization") >>> f.importSerialization() Traceback (most recent call last): File "", line 1, in AttributeError: Factory instance has no attribute 'importSerialization' }}}