[Zope3-Users] Design question (object or interface for category implementation?)

Garanin Michael garanin at m-lan.ru
Wed Mar 7 06:26:42 EST 2007


Christophe Combelles wrote:
> .....
> I want to define objects that represent Companies.
> A company can be either a client, or a provider, or both,
> or in the future it could be of another type.
>
> When the user creates a company, it must choose "client", "provider", 
> or both.
> The choice would assign a different interface to the object:
> IClient, or IProvider, and this would lead to different views for 
> these objects.
>
> So "client" and "provider" are categories of companies.
>
> So I would tend to have:
>
> class ICompany(Interface)
>
> class IClient(ICompany)
>
> class IProvider(ICompany)
>
> This is simple, but now how do I assign a name to these interface, so 
> that the user will choose between "Client" and "Provider", and not 
> between "IClient" and "IProvider"?
> Is it feasible with Tagged Value ?  Or with the "name" attribute in 
> the zope:interface ZCML declaration?
simple way:
1) in "interfaces.py":
class IMyApplicationSite(Interface):
    pass
class ICompany(Interface):
    pass

class IClientMarker(Interface):
    pass
class IProviderMarker(Interface):
    pass


2): in "model.py"
class MyApplicationSite(Folder):
     def get(self, key, default):
          obj = Folder.get(key, default)
          if ICompany.providedBy(obj):
             if 'client' in obj.tags:
                 directlyProvide(IClientMarker, obj)
             elif 'provider' in obj.tags:
                 directlyProvide(IProviderMarker, obj)
           return obj
 
class BaseCompany(Persistent):
    implements(ICompany)
     tags = "client provider"  # or "provider"


3) in "configure.zcml"
  <view
      for=".interfaces.IMyApplicationSite"
      type="zope.publisher.interfaces.browser.IBrowserRequest"
      provides="zope.publisher.interfaces.browser.IBrowserPublisher"
      factory="zope.app.container.traversal.ContainerTraverser"
      permission="zope.View"
      
allowed_interface="zope.publisher.interfaces.browser.IBrowserPublisher"
      />

 















More information about the Zope3-users mailing list