Created
May 25, 2012 04:01
-
-
Save sanpingz/2785671 to your computer and use it in GitHub Desktop.
状态模式
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static com.mceiba.util.Print.*; | |
class Actor{ | |
public void act() {} | |
} | |
class HappyActor extends Actor{ | |
public void act() { println("HappyActor"); } | |
} | |
class SadActor extends Actor{ | |
public void act() { println("SadActor"); } | |
} | |
class Stage{ | |
private Actor actor = new HappyActor(); | |
public void change() { actor = new SadActor(); } | |
public void performPlay() { actor.act(); } | |
} | |
public class State{ | |
public static void main(String[] args){ | |
Stage stage = new Stage(); | |
stage.performPlay(); | |
stage.change(); | |
stage.performPlay(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment