Added state pattern sample
This commit is contained in:
21
state/src/main/java/com/iluwatar/AngryState.java
Normal file
21
state/src/main/java/com/iluwatar/AngryState.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public class AngryState implements State {
|
||||
|
||||
private Mammoth mammoth;
|
||||
|
||||
public AngryState(Mammoth mammoth) {
|
||||
this.mammoth = mammoth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void observe() {
|
||||
System.out.println(String.format("%s is furious!", mammoth));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnterState() {
|
||||
System.out.println(String.format("%s gets angry!", mammoth));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user