# HG changeset patch # User Thierry Florac # Date 1529417363 -7200 # Node ID c3e3a8416bd7c2d4a57f0cbcfb3a2793ce6337e8 # Parent 8953ed9beeba7ece77999df0e018c48b4422c4fb Updated docstring diff -r 8953ed9beeba -r c3e3a8416bd7 src/pyams_utils/factory.py --- a/src/pyams_utils/factory.py Tue Jun 19 11:54:53 2018 +0200 +++ b/src/pyams_utils/factory.py Tue Jun 19 16:09:23 2018 +0200 @@ -10,6 +10,45 @@ # FOR A PARTICULAR PURPOSE. # +"""Objects factory management + +This module provides a decorator and a small set of functions to handle object factories. + +Instead of directly using a class as an object factory, the object of this module is to +let you create an object based on an interface. The first step is to create an object +implementing this interface, and then to register it as a factory: + +.. code-block:: python + + @implementer(IMyInterface) + class MyClass(object): + '''Class implementing my interface''' + + register_factory(IMyInterface, MyClass) + +Factory registry can also be handle by a decorator called "factory_config": + +.. code-block:: python + + @implementer(IMyInterface) + @factory_config(IMyInterface) + class MyClass(object): + '''Class implementing my interface''' + +When a factory is registered, you can look for a factory: + +.. code-block:: python + + factory = get_object_factory(IMyInterface) + if factory is not None: + myobject = factory() + else: + myobject = MyDefaultImplementation() + +By registering their own objects factories, extension packages can easily provide their +own implementation of any PyAMS interface handled by factories. +""" + __docformat__ = 'restructuredtext'