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 1054419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:24:14+00:00 2026-05-16T17:24:14+00:00

Consider a case of a form that is getting its data from a service

  • 0

Consider a case of a form that is getting its data from a service and is implemented using the MVP pattern. Do I need to isolate the service access in a separate class or it can be kept in the Model class itself. In my particular case, the model class only acts as a pass through to the data access class that eventually calls the service. The data access class has logic that is used for service callbacks and querying the service in specific time intervals for any updates.

I am asking this, because I would like to keep my code structure as simple as possible and only use additional classes if needed. But I also do not want to simplify it so much that future maintenance/extension can become very difficult.

  • 1 1 Answer
  • 0 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-16T17:24:15+00:00Added an answer on May 16, 2026 at 5:24 pm

    Simple code structure (meaning small number of classes) does not necessarily mean easy maintenance (see Ayende’s recent post on this). My suggestion is to keep to the Single Responsibility Principle (SRP). A Model’s responsibility in MVP is to encapsulate data to the view, but in your case it gets another responsibility: fetching the data from the service. Apart from this overloading of responsibilities, I see two other problems with this:

    1. What happens if the call to the service fails? Then you’ll be forced to handle this in view’s code.
    2. What responsibilities does the presenter have in your case?

    It seems to me your architecture isn’t really MVP (but without seeing the code, I might be wrong).

    Also, the actual implementation of MVP pattern depends on the GUI technology you are using. My general suggestions:

    • Stick to the Passive View pattern.
    • Keep the model dumb. I generally use simple POCO/POJO classes, no callbacks. I use C# view events in WinForms to notify the presenter about any UI events.
    • Make the model view-friendly: models should generally be implemented for view’s needs, so that the view code is kept to the minimum.
    • Presenter is the king. Keep all the business logic inside presenters (and other services/repositories).

    UPDATE: answer to your comment:

    • Yes, you should store the data in your model.
    • If I understand correctly, you expose events/callbacks in the model for handling exceptions. Then you let the view fetch data, and in case a service call fails, the presenter handles this by (again) calling the view to let the user know the service failed. I see several problems with this approach:

      1. It can create convoluted execution paths when a service exception occurs: presenter -> view -> model -> presenter -> view. This can be tricky to debug and unit test.
      2. How do you know where the view was (in terms of filling the view with the model data) when the exception occurred?

    My usual approach is for the presenter to do all the fetching and exception handling before the view gets its hands on the model data. That way I don’t need any callbacks in the model, since I can handle exceptions with simple try-catch blocks in the presenter. The model becomes just a holder of static data and not a gateway to backend services.

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

Sidebar

Related Questions

I'm using LINQ to query data. Consider a case where the user only wants
for example if we consider the case for 3 places with numbers from [1..3]..we
Consider the case where we might want to make use of a service, such
Consider a hypothetical case where I have to retrieve some details from the database
Consider a dummy case: <h:form id=wrapperForm> <h:panelGroup id=rowsContainer> <h:dataTable id=rowsTable value=#{bean.rows} var=row > <h:column>
I have query that is build from user's inputs ( passed via html form).
Consider this case: public Class1 { public static final String ONE = ABC; public
Consider the case of blogspot.com the domain is the one blogspot.com only but suppose
Consider the following case: public class A { public A() { b = new
Consider the following use case 1. User selects a product to purchase on seller's

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.