BAEL-1997 add additional method to the states
This commit is contained in:
parent
26a28dd663
commit
7c422c70ad
|
@ -12,8 +12,14 @@ public class DeliveredState implements PackageState {
|
|||
pkg.setState(new OrderedState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStatus() {
|
||||
System.out.println("Package delivered to post office, not received yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeliveredState{}";
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,11 @@ public class OrderedState implements PackageState {
|
|||
System.out.println("The package is in it's root state.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStatus() {
|
||||
System.out.println("Package ordered, not delivered to the office yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OrderedState{}";
|
||||
|
|
|
@ -19,4 +19,8 @@ public class Package {
|
|||
public void nextState() {
|
||||
state.next(this);
|
||||
}
|
||||
|
||||
public void printStatus() {
|
||||
state.printStatus();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,4 +5,6 @@ public interface PackageState {
|
|||
void next(Package pkg);
|
||||
|
||||
void prev(Package pkg);
|
||||
|
||||
void printStatus();
|
||||
}
|
|
@ -16,6 +16,11 @@ public class ReceivedState implements PackageState {
|
|||
pkg.setState(new DeliveredState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStatus() {
|
||||
System.out.println("Package was received by client.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ReceivedState{}";
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.baeldung.state;
|
||||
|
||||
public class StateDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Package pkg = new Package();
|
||||
pkg.printStatus();
|
||||
|
||||
pkg.nextState();
|
||||
pkg.printStatus();
|
||||
|
||||
pkg.nextState();
|
||||
pkg.printStatus();
|
||||
|
||||
pkg.nextState();
|
||||
pkg.printStatus();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue