Java 11 migraiton: model-view-controller
This commit is contained in:
@@ -47,9 +47,9 @@ public class App {
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// create model, view and controller
|
||||
GiantModel giant = new GiantModel(Health.HEALTHY, Fatigue.ALERT, Nourishment.SATURATED);
|
||||
GiantView view = new GiantView();
|
||||
GiantController controller = new GiantController(giant, view);
|
||||
var giant = new GiantModel(Health.HEALTHY, Fatigue.ALERT, Nourishment.SATURATED);
|
||||
var view = new GiantView();
|
||||
var controller = new GiantController(giant, view);
|
||||
// initial display
|
||||
controller.updateView();
|
||||
// controller receives some interactions that affect the giant
|
||||
|
@@ -30,7 +30,7 @@ public enum Fatigue {
|
||||
|
||||
ALERT("alert"), TIRED("tired"), SLEEPING("sleeping");
|
||||
|
||||
private String title;
|
||||
private final String title;
|
||||
|
||||
Fatigue(String title) {
|
||||
this.title = title;
|
||||
|
@@ -28,14 +28,15 @@ package com.iluwatar.model.view.controller;
|
||||
*/
|
||||
public class GiantController {
|
||||
|
||||
private GiantModel giant;
|
||||
private GiantView view;
|
||||
private final GiantModel giant;
|
||||
private final GiantView view;
|
||||
|
||||
public GiantController(GiantModel giant, GiantView view) {
|
||||
this.giant = giant;
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public Health getHealth() {
|
||||
return giant.getHealth();
|
||||
}
|
||||
@@ -44,6 +45,7 @@ public class GiantController {
|
||||
this.giant.setHealth(health);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public Fatigue getFatigue() {
|
||||
return giant.getFatigue();
|
||||
}
|
||||
@@ -52,6 +54,7 @@ public class GiantController {
|
||||
this.giant.setFatigue(fatigue);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public Nourishment getNourishment() {
|
||||
return giant.getNourishment();
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ public enum Health {
|
||||
|
||||
HEALTHY("healthy"), WOUNDED("wounded"), DEAD("dead");
|
||||
|
||||
private String title;
|
||||
private final String title;
|
||||
|
||||
Health(String title) {
|
||||
this.title = title;
|
||||
|
@@ -30,7 +30,7 @@ public enum Nourishment {
|
||||
|
||||
SATURATED("saturated"), HUNGRY("hungry"), STARVING("starving");
|
||||
|
||||
private String title;
|
||||
private final String title;
|
||||
|
||||
Nourishment(String title) {
|
||||
this.title = title;
|
||||
|
Reference in New Issue
Block a user