PEP: Contract Suppliers

In applications, some classes have a central role and are used by numerous other classes.

IReader is an interface that describe a contract.

Reader supplies IReader contract.

>>> from openalea.vpltk.catalog.catalog import Catalog
>>> catalog = Catalog()

Two appraoches are available. First one uses methods to search suppliers. It allows to pass numerous parameters to specify research. The second one use attributes approach. Syntax is easier but less powerful.

Method approach

To get a supplier of IReader : To get a facotry of IHelper suppliers (for example to create several instances) : To get interface class :

>>> service = catalog.supplier('IHelper')
>>> facotry = catalog.factory('IHelper')
>>> interface = catalog.interface('IHelper')

>>> suppliers = catalog.suppliers('IHelper')
>>> factories = catalog.factories('IHelper')

>>> service_xyz = catalog.service(identifier='Xyz')

Direct approach

>>> service = catalog.helper
>>> factory = catalog.Helper
>>> interface = catalog.IHelper

>>> suppliers = catalog.helpers
>>> factories = catalog.Helpers

>>> catalog.tags = ['PyQt4']

>>> catalog.IHelper.tags = ['PyQt4']
>>> service = catalog.helper

>>> catalog.IHelper.name = 'Xyz'
>>> service_xyz = catalog.helper

This approach maybe be attractive but is too implicit and so too dangerous.

Warning

This approach has been rejected

Table Of Contents

Previous topic

PEP: Project

Next topic

PEP: Declarative Language to Design GUI

This Page