WEB
ѧԺWEBJsp ״̬ģʽ֮ǼӦ Ķ

״̬ģʽ֮ǼӦ

2008-01-05 20:17:56ԴWEB
ʾһж״̬ڲͬ״̬£״̬ģʽ֮ǼӦã ͬһַвͬΪswich-case䣬ʵ־fire

һж״̬ڲͬ״̬£ ͬһַвͬΪswich-case䣬д֧߼һ״̬ģʽÿ״̬װһУö̬ʹòͬ״̬ͬһֲַͬΪ

״̬ģʽUMLͼ£

״̬ģʽ֮ǼӦ

ǼĻǹMarine״̬ͨ״̬ʹ˷״̬״̬»ǹĿǹƵDzͬģ״̬ģʽʵֻǹfire()

 

ȶ״̬Stateӿڣӿָ˻ǹfireΪ

public interface State {
  public void fire();
}

Stateӿһfire()ʵNormalStateExcitedStateֱʾͨ״̬ʹ˷״̬ʵ־fire

public class NormalState implements State {
  public void fire() {
 System.out.PRintln("ͨ״̬ÿ뿪ǹ1Ρ");
  }
}
public class ExcitedState implements State {
  public void fire() {
 System.out.println("˷״̬ÿ뿪ǹ2Ρ");
  }
}
 
ۡ

Tags״̬ ģʽ Ǽ

༭¼룺ˬˬ[] [ ӡ]