Data access from multiple code modules

Fredrik Lundh fredrik at pythonware.com
Thu Jul 13 08:38:17 EDT 2006


simon.hibbs at gmail.com wrote:

> So I instantiate a Model object that handles all IO to the database.
> Next I instantiate a Controller object, passing it a reference to the
> Data/IO model object. Next I instantiate the display panel objects for
> the GUI, passing them references to the Controller object.
>
> The Controller object contains the logic for all the transformations I
> want to perform on the data.

sounds reasonable.

note that for simple applications, you can put the controller logic in the Model
object, and let the UI call the relevant methods directly.  however, putting con-
troller logic in the UI code is almost never a good idea.

or in other words, if "do_update" is an UI callback that's called when the user
clicks "Update" in your UI, doing

    def do_update(self):
        self.controller.update()

or

    def do_update(self):
        self.model.update()

is perfectly okay, but

    def do_update(self):
        sum = 0
        for record in self.model.select(...):
            sum = some operation
        self.model.update(...)

isn't a good idea.

</F> 






More information about the Python-list mailing list