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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:00:40+00:00 2026-06-08T00:00:40+00:00

I am developing an editor following the general MVC design: the model holds the

  • 0

I am developing an editor following the general MVC design: the model holds the data, the controller knows how to change it, and the view issues calls the controller to query and modify the model. For the sake of argument, let us use

public class Model {
    public Object getStuff(String id);
    public void setStuff(String id, Object value);    
}    

public interface Controller {
    public void execute(Command command);
    public void redo();
    public void undo();     
    public void save();
    public void load(File f);
}

The class that actually implements the controller holds a reference to the model; commands need to access it too, so they must all provide a void execute(Model m); interface that actually grants them this access only when needed.

However, views generally need access to the model – when building themselves and, later on, to listen for changes and refresh themselves accordingly. I am afraid that adding a “Model getModel()” call to the Controller will result in a great temptation to bypass the execute() mechanism; and I am not the only developer working on the project. Given this scenario, how would you enforce an “all changes go through the controller” policy?

Two alternatives I am considering:

  • An interface called “ReadOnlyModel”, returned by the getModel() call instead of the real model, that catches any such attempts.
  • Lots of comments to clue incoming developers as to the Correct Way of Doing Things
  • 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-06-08T00:00:43+00:00Added an answer on June 8, 2026 at 12:00 am

    I recommend modeling the access to the model as a set of classes. For example, if the view needs to modify a customer’s attributes, there would be a ModifyCustomerCommand class that would have as properties all of the information needed in order to perform the update. The view would construct an instance of the class with values and pass it back to the controller which, in turn, would pass the command back to the model for the actual update.

    A benefit from this approach is that each of these model access commands can implement undo behavior. If the controller keeps an ordered collection of these commands as they get sent back to the model, the controller can back off the changes, one at a time, by invoking the undo method on the most recently executed command.

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

Sidebar

Related Questions

I'm developing a simple text editor for iPad. Instead of Core Data, the app
I'm developing (.NET MVC) a large website which has the following specifications: Database pages
I am developing a level editor in Xna and my question is that when
I have been developing a toy editor, and I want my editor to look
Hi i am developing game level editor.Currently I am using win32 with directX.But with
i dont how to solve this problem. I am developing a graphical editor, where
I am developing visual game level editor in C++. For this I want reflection(RTTI)
I'm developing a simple Text Editor to understand better PocketC language, then I've done
The question of today is the following: I'm developing a code generator for my
I am developing an editor and I need to know how to apply drag

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.