Formatted all files to the same standard
This commit is contained in:
@ -7,7 +7,7 @@ public class AngryState implements State {
|
||||
public AngryState(Mammoth mammoth) {
|
||||
this.mammoth = mammoth;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void observe() {
|
||||
System.out.println(String.format("%s is furious!", mammoth));
|
||||
|
@ -1,22 +1,22 @@
|
||||
package com.iluwatar;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* In State pattern the object (Mammoth) has internal state object (State) that
|
||||
* defines the current behavior. The state object can be changed to alter the
|
||||
* behavior.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Mammoth mammoth = new Mammoth();
|
||||
mammoth.observe();
|
||||
mammoth.timePasses();
|
||||
mammoth.observe();
|
||||
mammoth.timePasses();
|
||||
mammoth.observe();
|
||||
Mammoth mammoth = new Mammoth();
|
||||
mammoth.observe();
|
||||
mammoth.timePasses();
|
||||
mammoth.observe();
|
||||
mammoth.timePasses();
|
||||
mammoth.observe();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,16 +3,16 @@ package com.iluwatar;
|
||||
/**
|
||||
*
|
||||
* Mammoth has internal state that defines its behavior.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class Mammoth {
|
||||
|
||||
|
||||
private State state;
|
||||
|
||||
public Mammoth() {
|
||||
state = new PeacefulState(this);
|
||||
}
|
||||
|
||||
|
||||
public void timePasses() {
|
||||
if (state.getClass().equals(PeacefulState.class)) {
|
||||
changeStateTo(new AngryState(this));
|
||||
@ -25,12 +25,12 @@ public class Mammoth {
|
||||
this.state = newState;
|
||||
this.state.onEnterState();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "The mammoth";
|
||||
}
|
||||
|
||||
|
||||
public void observe() {
|
||||
this.state.observe();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public class PeacefulState implements State {
|
||||
|
||||
|
||||
private Mammoth mammoth;
|
||||
|
||||
public PeacefulState(Mammoth mammoth) {
|
||||
@ -17,5 +17,5 @@ public class PeacefulState implements State {
|
||||
public void onEnterState() {
|
||||
System.out.println(String.format("%s calms down.", mammoth));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,12 +3,12 @@ package com.iluwatar;
|
||||
/**
|
||||
*
|
||||
* State interface.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface State {
|
||||
|
||||
void onEnterState();
|
||||
|
||||
|
||||
void observe();
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user