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