[Zope3-Users] ZopeX3 Component Architecture in comparision to MVC - general question/example

Reinhold Strobl reinhold.strobl at gmx.net
Tue Feb 28 10:27:58 EST 2006


Hi,

I know from http://philikon.de/files/zope3-for-zope2-developers.pdf that ZopeX3
Component Architecture is more/differs than/to Model-View-Controller.

Model = Content in Zope
View = Views in Zope

but what about the controller? Where should I place the application logic? I
mean, I will explain my problem with a example. 

I'd like to develop a server component, that simple calculates a sum. The
component should be reachable via XML-RPC. So that the client somehow calls the
server compoment to calculate a sum. You see, the server component need not to
store any information, because it simple has one function. How should I
implemented that task in Python/Zope. I mean, if I compare it to the
Modell-View-Controller again, there is no real Model, because there is no need
for peristence. 

I have tried to solve the problem in the following way:

1. Define an interface:
=====
from zope.interface import Interface
from zope.schema import List, Text, TextLine, Int

class ICalculator(Interface):
    """Store information about a calculator.
    """

    def add(arg1, arg2):
        """ Calculates des sum of the two arguments """


2. Define an Object:
=====
from persistent import Persistent
from zope.interface import implements
from simple.interfaces import ICalculator

class Calc:
    implements(ICalculator)

    def add(self, arg1, arg2):
        return arg1 + arg2

3. Define the XML-RPC View:
=====
from zope.schema import getFields
from zope.app.publisher.xmlrpc import XMLRPCView
from simple.interfaces import ICalculator

def to_unicode(string):
    if isinstance(string, unicode):
        return string
    return string.decode('utf-8')

class CalcView(XMLRPCView):

    def calc(self, arg1, arg2):
        context = self.context

        return context.add(arg1,arg2)

=======================================
My overall question is now, is that ok? Or should I use utilities instead of
(content) components if no persistence is required? I believe this is general
question in development components, isn't it?

Thanks a lot in advance,
best regards
Reinhold Strobl




More information about the Zope3-users mailing list