Anywhere

水中苇
随笔 - 28, 文章 - 3, 评论 - 0, 引用 - 0
数据加载中……

state模式

主要是用来处理状态改变的.
先看一下代码:
class Context;
class state
{
 
public:
   state();
   
virtual ~state();
   virtaul   
void ShowState();
}
;
class childA:public state
{
  
public:
    childA();
    
~childA();
    
void ShowState();
    
void changeState(Context *pCtxt;)
        
{pCtxt->changeState(new childB());}
}
;
class childB:public state
{
  
public:
    childB();
    
~childB();
    
void ShowState();
    
void changeState(Context *pCtxt)
        
{pCtxt->changeState(new childA());}

}
;
class Context
{
  
public:
       Context(state *);
       void setState(state *);
    
void showState();
    
void changeState(state *);
  
private:
    friend 
class state;
    state 
*_state;
   
}
;

posted on 2009-08-13 10:25 三水寿 阅读(411) 评论(0)  编辑 收藏 引用 所属分类: 设计模式学习笔记----行为模式


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理