Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4058106
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:02:16+00:00 2026-05-20T15:02:16+00:00

I have a design question about the communication between the model and the presenter

  • 0

I have a design question about the communication between the model and the presenter in the MVP design pattern — or more accurately its derived form the passive view.

Let’s assume the following simple GUI as an example: I have a window where my view is a list and there is the possibility to open a file dialog to select a file. Once I’ve finished my selection the file shall be appended to the list.

My model shall be the collection of all files I have opened.

A straight-forward implementation comes to mind (pseudo python code):

Solution A

class Model():
     def add(filename):
         # add file
         ...
         # return True if successful
         return True

class Presenter():
    # event from GUI
    def onFileOpen():
        filename = FileSelectorStuff()
        isFileAdded = model.add(filename)
        if isFileAdded:
            view.insertItem(filename)

In this case I know that the file was added to the model and thus I update the view accordingly.

On the other hand I could add the file to the model, and then wait for the model to notify me that is has changed and that the presenter has to update the view, like so:

Solution B

class Model():
     def add(filename):
         # add file
         ...
         # alert controller
         modelChanged(Type.FileAdded, filename)

class Presenter():
    # event from GUI
    def onFileOpen():
        filename = FileSelectorStuff()
        model.add(filename)

    # event from model
    def onModelChanged(type, filename):
        if type == Type.FileAdded:
            view.insertItem(filename)
        elif type == Type.FileRemoved:
            ...

Now, in this case both implementations work just fine. But let’s assume that the model also monitors the files and needs to tell the presenter when one of them has been deleted, for example. Then I need this kind of onModelChanged() callback mechanism anyway.

My question now is: Should I mix the two ways for updating the view (A for synchronous updates, and B for async) or rather keep it all central in one place as proposed in solution B?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:02:17+00:00Added an answer on May 20, 2026 at 3:02 pm

    This problem is probably long solved, but I hit it from a search engine so here’s my answer:

    Use B. Forget mixing.

    If you want add in bits of A for efficiency you’ll have to have two methods for the model: one returning a boolean, the other emitting events. If the synchronous Model.add method emits events, then the event handler in the presenter will have to ignore them during that method call. Messy.

    However my understanding of Passive View suggests that the Presenter is the one in charge of updating the Model, so it might be argued that it should be the one to remove files from the Model, anyway. This paves the way for a A only solution.

    My Final Answer:
    Use A, or use B. Don’t mix.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about best practices with the Module Design Pattern. The code
I have a design question about the use of Hibernate annotations and DAO pattern.
I have posted a question about multilanguage database design here, [] What are best
This is more of a design question. I have a template class, and I
This is more of a general design question I guess... I have an Ajax
More of a design/conceptual question. At work the decision was made to have our
This is probably more a design or style question: I have just been considering
I have a question regarding my database design and its implementation that i am
I have small design question about html.DropDownListFor() How can I change width of html.DropDownListFor()
I have a question about usability/design. I currently am using some JQuery to hide/show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.