: .
, , . , - , .
, , __init__ ! , ( Python). __init__ , , () __init__ ( ).
, , , , .
, . Python, . directlyProvides, , . @provider() classProvides moduleProvides , .
factory; - , , factory __call__, , . factory:
from zope import interface
class ITest(interface.Interface):
required_attribute = interface.Attribute(
"""A required attribute for classes implementing this interface.""")
def required_method():
"""A required method for classes implementing this interface."""
class ITestFactory(interface.Interface):
"""Creates objects providing the ITest interface"""
def __call__(a, b):
"""Takes two parameters"""
@interface.implementer(ITest)
@interface.provider(ITestFactory)
class Test(object):
def __init__(self, a, b):
self.required_attribute = a*b
def required_method():
return self.required_attribute
zope.component class , getInterfaces , . IFactory, __init__:
from zope import component
class ITestFactory(component.interfaces.IFactory):
"""Creates objects providing the ITest interface"""
def __call__(a, b):
"""Takes two parameters"""
testFactory = component.Factory(Test, 'ITest Factory', ITestFactory.__doc__)
interface.directlyProvides(testFactory, ITestFactory)
factory zope.component, , ITestFactory.
zope.interface.directlyProvides , factory ITestFactory, zope.component.Factory IFactory.