Presentation Model pulls the state and behavior of the view out into a model class that is part of the presentation.
## Explanation
Real world example
> When we need to write a program with GUI, there is no need for us to put all presentation behavior in the view class. Because it will test become harder. So we can use Presentation Model Pattern to separate the behavior and view. The view only need to load the data and states from other class and show these data on the screen according to the states.
In plain words
> a pattern that used to divide the presentation and controlling.
Code Example
Class `view` is the GUI of albums. Methods `saveToPMod` and `loadFromPMod` are used to achieve synchronization.
// other get methods are like this, which are used to get information of selected album.
publicvoidsetTitle(finalStringvalue){
LOGGER.info("Change album title from {} to {}",
selectedAlbum.getTitle(),value);
selectedAlbum.setTitle(value);
}
// other set methods are like this, which are used to get information of selected album.
/**
* Gets a list of albums.
*
* @return the names of all the albums.
*/
publicString[]getAlbumList(){
varresult=newString[data.getAlbums().size()];
for(vari=0;i<result.length;i++){
result[i]=data.getAlbums().get(i).getTitle();
}
returnresult;
}
}
```
We can run class `App` to start this demo. the checkbox is the album classical; the first text field is the name of album artist; the second is the name of album title; the last one is the name of the composer: