How to separate the model from the view?

I have a bunch of model objects.

These objects end up being rendered as views (say forms) in a rich client app.

I started to annotate the fields in the model objects (Java annotations) with things that let me render them as forms on the fly (e.g displayname, group, page, validvalues).

I now realise that the view has crept into the model.

How should I seperate the view logic out of the model objects?

TECH: Java, Java Annotations, Eclipse RCP

EDIT:My question is theoretic, but I would also like some concrete (implementation) advice.


At the risk of stating the obvious, what you need to do is store the display-related information somewhere else. Don't put the page in the model code - create an object for the interface, have it contain page objects, and make each page know what values it displays. This may require a certain amount of refactoring.

Having said that, not everything you mention is 'view'. Valid values for a field is part of the logic of the field; it should be considered part of the model, not the view. Likewise if 'group' is a logical grouping, rather than about placement in the interface, it might be considered part of the model.


You could look at the MVC pattern and introduce a controller into the mix to provide the communication between the model and the view.

This prevents the view creeping into the model as the view never talks to the model it only talks to the controller which is responsible for all interaction between the model and the view


I get a lot of IndexOutOfBoundsException from the any Arraylist I use. Most of the times it works fine but sometimes I get this annoying error on Arraylists i use on my project. The main cause is ...

I have multiple JREs installed (6,7,8 both 32 and 64 bit). The way I have set things up is that I have the set up a number of JAVA_x_HOME paths and then reference JAVA_HOME=%JAVA_x_HOME% depending on ...

Edit: I am using quartz-2.1.5.jar. Here's the summary of my classes: HttpPollingJob extends PollingJob extends ScheduledJob implements org.quartz.Job Specifically: 1) ScheduledJob implements ...

How I can get the ID of a saved object. please give me an idea. because I am a beginner in grails def saveCandidates(){ def candidate=new Candidates( name: request....