java_设计模式_状态模式_State Pattern(2016-08-16)
定义:
当一个对象的内在状态改变时允许改变其行为,这个对象看起来像是改变了其类。
类图:
状态模式所涉及到的角色有:
状态的维护和转换:
维护状态的数据,给状态设置不同的状态值;状态的转换,指的是根据状态的变化来选择不同的状态处理对象。
有两个地方可以进行状态的维护和转换:
① 在Context 中。
② 在状态的处理类中。
如何选择者两种方式:
● 如果状态转换的规则是一定的,一般不需要进行什么扩展规则,那么就适合在上下文中统一进行状态的维护。
● 如果状态的转换取决于前一个状态动态处理的结果,或者是依赖外部数据,为了增强灵活性,这种情况下,一般式在状态处理类中进行状态的维护。
使用场景:
考虑一个在线投票系统的应用,要实现控制同一个用户只能投一票,如果一个用户反复投票,而且投票次数超过5次,则判定为恶意刷票,要取消该用户投票的资格,当然同时也要取消他所投的票;如果一个用户的投票次数超过8次,将进入黑名单,禁止再登录和使用系统。
要使用状态模式实现,首先需要把投票过程的各种状态定义出来,根据以上描述大致分为四种状态:正常投票、反复投票、恶意刷票、进入黑名单。然后创建一个投票管理对象(相当于Context)。
/**
* 投票状态接口 <br>
* 抽象状态(State)角色
*/
public interface VoteState { /**
* 处理状态对应的行为
* @param user 投票人
* @param voteItem 投票项
* @param manager 投票上下文,用来实现状态对应的功能处理的时候,可以回调上下文的数据
*/
public void vote(String user, String voteItem, VoteManager manager);
} /**
* 正常投票状态 <br>
* 具体状态(ConcreteState)角色
*/
public class NormalVoteState implements VoteState { @Override
public void vote(String user, String voteItem, VoteManager manager) {
manager.getMapVote().put(user, voteItem);
System.out.println("恭喜你投票成功!");
}
} /**
* 反复投票状态 <br>
* 具体状态(ConcreteState)角色
*/
public class RepeatVoteState implements VoteState { @Override
public void vote(String user, String voteItem, VoteManager manager) {
System.out.println("请不要重复投票!");
}
} /**
* 恶意刷票状态 <br>
* 具体状态(ConcreteState)角色
*/
public class SpiteVoteState implements VoteState { @Override
public void vote(String user, String voteItem, VoteManager manager) {
String s = manager.getMapVote().get(user);
if(s != null){
manager.getMapVote().remove(user);
}
System.out.println("你有恶意刷票行为,取消投票资格。");
}
} /**
* 黑名单状态 <br>
* 具体状态(ConcreteState)角色
*/
public class BlackVoteState implements VoteState { @Override
public void vote(String user, String voteItem, VoteManager manager) {
System.out.println("进入黑名单,将禁止登陆和使用本系统。");
}
} /**
* 投票管理对象 <br>
* 环境(Context)角色
*/
public class VoteManager { /**
* 持有状态处理对象
*/
private VoteState state = null;
/**
* 记录用户投票的结果,Map<String,String>对应Map<用户名,投票的选项>
*/
private Map<String, String> mapVote = new HashMap<String, String>();
/**
* 记录用户投票次数,Map<String,Integer> 对应Map<用户名,投票的次数>
*/
private Map<String, Integer> mapVoteCount = new HashMap<String, Integer>();
/**
* 获取记录用户投票结果的Map
* @return 记录用户投票结果的Map
*/
public Map<String, String> getMapVote() {
return mapVote;
}
/**
* 投票
* 在Context 中进行状态的维护和转换
* @param user 投票人
* @param voteItem 投票的选项
*/
public void vote(String user, String voteItem){
Integer oldVoteCount = mapVoteCount.get(user);
if(oldVoteCount == null){
oldVoteCount = 0;
}
oldVoteCount++;
mapVoteCount.put(user, oldVoteCount);
if(oldVoteCount == 1){
state = new NormalVoteState();
}else if(oldVoteCount > 1 && oldVoteCount < 5){
state = new RepeatVoteState();
}else if(oldVoteCount >= 5 && oldVoteCount < 8){
state = new SpiteVoteState();
}else if(oldVoteCount >= 8){
state = new BlackVoteState();
}
state.vote(user, voteItem, this);
}
} /**
* 客户端<br>
*/
public class Client { public static void main(String[] args) {
VoteManager manager = new VoteManager();
for(int i = 0; i < 8; i++){
manager.vote("JOE", "A");
}
}
}
◆ 在状态处理类中进行状态的维护和转换
/**
* 投票状态接口 <br>
* 抽象状态(State)角色
*/
public interface VoteState { /**
* 处理状态对应的行为
* @param user 投票人
* @param voteItem 投票项
* @param manager 投票上下文,用来实现状态对应的功能处理的时候,可以回调上下文的数据
*/
public void vote(String user, String voteItem, VoteManager manager);
} /**
* 正常投票状态 <br>
* 具体状态(ConcreteState)角色
*/
public class NormalVoteState implements VoteState { @Override
public void vote(String user, String voteItem, VoteManager manager) {
manager.getMapVote().put(user, voteItem);
System.out.println("投票成功!");
manager.getMapState().put(user, new RepeatVoteState());//在状态处理类中进行状态的维护和转换
}
} /**
* 反复投票状态 <br>
* 具体状态(ConcreteState)角色
*/
public class RepeatVoteState implements VoteState { @Override
public void vote(String user, String voteItem, VoteManager manager) {
System.out.println("请不要重复投票。");
if(manager.getMapVoteCount().get(user) >= 4){
manager.getMapState().put(user, new SpiteVoteState());//在状态处理类中进行状态的维护和转换
}
}
} /**
* 恶意刷票状态 <br>
* 具体状态(ConcreteState)角色
*/
public class SpiteVoteState implements VoteState { @Override
public void vote(String user, String voteItem, VoteManager manager) {
String s = manager.getMapVote().get(user);
if(s != null){
manager.getMapVote().remove(user);
}
System.out.println("你有恶意刷票行为,取消投票资格。");
if(manager.getMapVoteCount().get(user) >= 7){
manager.getMapState().put(user, new BlackVoteState());//在状态处理类中进行状态的维护和转换
}
}
} /**
* 黑名单状态 <br>
* 具体状态(ConcreteState)角色
*/
public class BlackVoteState implements VoteState { @Override
public void vote(String user, String voteItem, VoteManager manager) {
System.out.println("你进入了黑名单。");
}
} /**
* 投票管理对象 <br>
* 环境(Context)角色
*/
public class VoteManager { /**
* 记录当前每个用户对应的状态处理对象,每个用户当前的状态是不同的
* Map<String, VoteState>对应Map<用户名,当前对应的状态处理对象>
*/
private Map<String, VoteState> mapState = new HashMap<String, VoteState>();
/**
* 记录用户投票的结果,Map<String,String>对应Map<用户名,投票的选项>
*/
private Map<String, String> mapVote = new HashMap<String, String>();
/**
* 记录用户投票次数,Map<String,Integer> 对应Map<用户名,投票的次数>
*/
private Map<String, Integer> mapVoteCount = new HashMap<String, Integer>();
/**
* 获取记录用户投票结果的Map
* @return 记录用户投票结果的Map
*/
public Map<String, String> getMapVote() {
return mapVote;
}
/**
* 获取记录当前每个用户对应的状态处理对象
* @return
*/
public Map<String, VoteState> getMapState() {
return mapState;
}
/**
* 获取记录每个用户对应的投票次数的Map
* @return
*/
public Map<String, Integer> getMapVoteCount() {
return mapVoteCount;
} /**
* 投票
* @param user 投票人
* @param voteItem 投票的选项
*/
public void vote(String user, String voteItem){
Integer oldVoteCount = mapVoteCount.get(user);
if(oldVoteCount == null){
oldVoteCount = 0;
}
oldVoteCount++;
mapVoteCount.put(user, oldVoteCount); VoteState state = mapState.get(user);
if(state == null){
state = new NormalVoteState();
}
state.vote(user, voteItem, this);
}
} /**
* 客户端<br>
*/
public class Client { public static void main(String[] args) {
VoteManager manager = new VoteManager();
for(int i = 0; i < 8; i++){
manager.vote("JOE", "A");
}
}
}
认识状态模式
● 状态和行为
所谓对象的状态,通常指的就是对象实例的属性的值;而行为指的就是对象的功能,再具体点说,行为大多可以对应到方法上。
状态模式的功能就是分离状态的行为,通过维护状态的变化,来调用不同状态对应的不同功能。也就是说,状态和行为是相关联的,它们的关系可以描述为:状态决定行为。
由于状态是在运行期被改变的,因此行为也会在运行期根据状态的改变而改变。
● 行为的平行性
注意平行线而不是平等性。所谓平行性指的是各个状态的行为所处的层次是一样的,相互独立的、没有关联的,是根据不同的状态来决定到底走平行线的哪一条。行为是不同的,当然对应的实现也是不同的,相互之间是不可替换的。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAq0AAAC/CAIAAABbv3JFAAAgAElEQVR4nO2dTW/b1vav+WHILyFzkFEHB4EdZdRRIoMeZVLZIDLKIHYhwKPYDjQq4CiAUKConAAaxbVPoQPkHRWQkzg5qGCkjQtUTvP6b3mPY+f2Xt3B73phZfNFlB3JlPR7EBQUtblJiSrXs9d+sdUhhBBCyLhinfQFEEIIIeTEoAcQQggh4ws9gBBCCBlf6AGEEELI+EIPIIQQQsYXegAhhBAyvtADCCGEkPGFHkCGHu+7n9t/HsjL1qu90ubOESqp/vTymOX9+vOeKokjoRK//rz521+9VphffVra3An2/zb2t17ted/93Nh+3/MlfkrKS3KvPirf/r1rsdarvZRfY/vPA7/+PE1JQkgc9AAy9Dilh+7VR/Ky+dtfVvFf7tVHzd/+M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uVytVnWBIAiQ5y99CvbokuIQOh/QOKS/H4MQcqKc9INzjOjrfUzygJcvX570Zx8LXr582dd73DlMBsj4AL1+gHsIGvrtdhud/ZHzCDDXANvlclkrgs4H6Jf9/miEkJOCMWIw9DtGJHkAGTHQdpcxgNgol8t6NqAeHJDsAQY6H0AIIWRYoAeMC2imdzod13XR5S99//l8PrwwQEf1/et+AXoAIYSMEvSAsaCtlv4tl8to9JdKJcwUqNfrkQl8RH0N1h+MPAXe7d9HIIQQ0g/oAYQQQsj4Qg8ghBBCxhd6ACGEEDK+0AMIIYSQ8YUeQAghhIwv9ABCCCFkfKEHEEIIIePL/wMDA2yr1ZJSYQAAAABJRU5ErkJggg==" alt="" />
而平等性强调的是可替换性,大家是同一行为的不同描述或实现,因此在同一个行为发生的时候,可以根据条件挑选任意一个实现来进行相应的处理。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAd8AAADrCAIAAACn/gsAAAAfdElEQVR4nO3dz2vbaB7Hcf0xT/8JeQ46lyLRwoJPXpn6lEvlUnIyrG0o5BSnQ04BR4ESKHFayF6a2JQOpHEaOuDJL2gx+eGBSdLEbmm9G8uz3c0evtOHp5LtWLEky8nnRSm2LEtK/ORtRZYd6QIAAMJHGvYGAABAB6gzAEAYoc4AAGGEOgMAhBHqDAAQRqgzAEAYoc4AAGGEOgMAhBHqfN28rn7uOP1xqTa9+odz+k8/Vz6cnndb2q+/f72b3+m4zPvP3ve4Yz+OvrQvnefD6fnd/E4/K3pcqvWz0qfvTrp9iwBCBXUeGUvb9celWu9/j5b2JOOX+8/eO+9+6/HGrccbPExUxqfvTiTjl0dLe91W+uvvX3ss8KefK93u2LS+/fr71x7/7j97f+vxRj+Bpjn51W4V/unnyq3HG3fzO/SPNo9fFafferzRtL5dul6A4UKdR0bT+vZoac+WY+qRWGe6YKsPVfj+s/d0K/Xu19+/UtH43SlntvXSDHRZ3JUWp3ckbli3f0vbdeeXeTe/89PPFf7v1uMNyfiFX+32bEG30uWjL+1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2trbWY/m5XI4xls/nz8/P9/f3VVWlUvMZVFVdXl7mV/P5vCzLtEy+cFmWNzc3z8/P19bWKND8fGea7iHU2RXUGcD7Op+entIRCVuCOQq0bUqfdd7f36ddYF3XbcunAxTOqtL2iOHmR1ckSRLXu7a2lk6nxaZ7CHV2BXUGuFAU5d+eyufze3t7vedZXl4Wry4sLDgX4rzXgwcP0un0mzdvui12YWHh48ePtonpdNq2PXt7e2++672dHkKdXUGdAbyvM3SEOruCOgOgzgFBnV1BnQEuFEX5F/gPdXYFdQZAnQOCOruCOgNcKIrSBP+hzq6gzgCoc0BQZ1dQZwDUOSCosyuoM8CFoihfwX+osyuoMwDqHBDU2RXUGeBCUZQv4D/U2RXUGQB1Dgjq7ArqDHBx584dBfx3+/Zt1Ll/qDPAX44gKMN+qEcD6gzwl5OTk2FX60Y4OTkZ9kM9GlBnAIAwQp0BAMIIdQYACCPUGQAgjFBnAIAwQp0BAMIIdQYACKP/A0Sip/Q46dQ6AAAAAElFTkSuQmCC" alt="" />
大家可能会发现状态模式的结构和策略模式的结构完全一样,但是,它们的目的、实现、本质却是完全不一样的。还有行为之间的特性也是状态模式和策略模式一个很重要的区别,状态模式的行为是平行的,不可相互替换的;而策略模式的行为是平等性的,是可以相互替换的。
● 环境和状态处理对象
在状态模式中,环境(Context)是持有状态的对象,但是环境(Context)自身并不处理跟状态相关的行为,而是把处理状态的功能委托给了状态对应的状态处理类来处理。
在具体的状态处理类中经常需要获取环境(Context)自身的数据,甚至在必要的时候会回调环境(Context)的方法,因此,通常将环境(Context)自身当作一个参数传递给具体的状态处理类。
客户端一般只和环境(Context)交互。客户端可以用状态对象来配置一个环境(Context),一旦配置完毕,就不再需要和状态对象打交道了。客户端通常不负责运行期间状态的维护,也不负责决定后续到底使用哪一个具体的状态处理对象。
适用场景:
1.一个对象的行为取决于它的状态,并且它必须在运行时刻根据状态改变它的行为。
2.一个操作中含有庞大的多分支结构,并且这些分支决定于对象的状态。
参考粘贴来自:
http://www.cnblogs.com/java-my-life/archive/2012/06/08/2538146.html
http://joe5456536.blog.163.com/blog/static/85374773201192252829941/
java_设计模式_状态模式_State Pattern(2016-08-16)的更多相关文章
- java_设计模式_组合模式_Composite Pattern(2016-08-12)
概念: 组合模式(Composite Pattern)将对象组合成树形结构以表示“部分-整体”的层次结构,组合模式使得用户对单个对象和组合对象的使用具有一致性. 有时候又叫做部分-整体模式,它使我们树 ...
- java_设计模式_命令模式_Command Pattern(2016-08-09)
理解还不到位,先窜出来.等过一阵子再看,再理解. 定义:将一个请求封装成一个对象,从而让你使用不同的请求把客户端参数化,对请求排队或者记录请求日志,可以提供命令的撤销和恢复功能. 类型:行为类模式 类 ...
- java_设计模式_工厂模式_Factory Pattern(2016-08-04)
工厂模式主要是为创建对象提供了接口.工厂模式按照<Java与模式>中的提法分为三类: (1)简单工厂(Simple Factory)模式,又称静态工厂方法模式(Static Factory ...
- java_设计模式_迭代器模式_Iterator Pattern(2016-08-12)
迭代子(Iterator)模式又叫游标(Cursor)模式,是对象的行为模式. 定义:提供一种方法访问一个容器对象中各个元素,而又不暴露该对象的内部细节. 类型:行为类模式 类图: 如果要问java中 ...
- java_设计模式_外观模式_Facade Pattern(2016-08-09)
外观模式/门面模式 1.概念 为子系统中的一组接口提供一个统一接口.Facade模式定义了一个高层接口,这个接口使得这子系统更容易使用. 2.UML 由于外观模式的结构图过于抽象,因此把它稍稍具体点. ...
- java_设计模式_策略模式_Strategy pattern(2016-07-15)
感受:将算法从方法级别,提升到类级别.之后利用java多态,来切换不同的算法实现不同的功能. 在阎宏博士的<JAVA与模式>一书中开头是这样描述策略(Strategy)模式的: 策略模式属 ...
- 乐在其中设计模式(C#) - 状态模式(State Pattern)
原文:乐在其中设计模式(C#) - 状态模式(State Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 状态模式(State Pattern) 作者:webabcd 介绍 允 ...
- 二十四种设计模式:状态模式(State Pattern)
状态模式(State Pattern) 介绍允许一个对象在其内部状态改变时改变它的行为.对象看起来似乎修改了它所属的类. 示例有一个Message实体类,对它的操作有Insert()和Get()方法, ...
- [设计模式] 20 状态模式 State Pattern
在GOF的<设计模式:可复用面向对象软件的基础>一书中对状态模式是这样说的:允许一个对象在其内部状态改变时改变它的行为.对象看起来似乎修改了它的类.状态模式的重点在于状态转换,很多时候,对 ...
随机推荐
- Linux NTP校时
1.安装客户端(root权限运行) apt-get install ntpdate 2.修改配置文件:“/etc/default/ntpdate”, NTPSERVERS="ntp. ...
- HTML5与CSS3权威指南.pdf3
表单验证 <input name="text" type="text" required pattern="^\w.*$"> r ...
- Cogs 309. [USACO 3.2] 香甜的黄油 dijkstra,堆,最短路,floyd
题目:http://cojs.tk/cogs/problem/problem.php?pid=309 309. [USACO 3.2] 香甜的黄油 ★★ 输入文件:butter.in 输出文件 ...
- HW4.31
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- phonegap与google analytics整合
用phonegap开发的app接近尾声,需要整一个谷歌分析进去. 1.首先申请一个GA帐号,在“what would you like to track”下选择APP
- MySQL数据库MyISAM和InnoDB存储引擎的比较(转)
MySQL有多种存储引擎,MyISAM和InnoDB是其中常用的两种.这里介绍关于这两种引擎的一些基本概念(非深入介绍). MyISAM是MySQL的默认存储引擎,基于传统的ISAM类型,支持全文搜索 ...
- 【转】谁说Vim不是IDE?(三)
谁说Vim不是IDE?(三) 常用插件 之所以说Vim形成了自己的生态环境,就是因为Vim具备开放的插件体系,开发者为了提升开发效率,为Vim编写了数以万计的插件,我们可以根据需要任意选择,也可以 ...
- 在线App开发平台——应用之星傻瓜式开发平台
随着智能手机及APP应用程序的普及,越来越多的企业和个人意识到APP的营销价值,出于对技术的敬畏,很多企业下意识认为开发APP是一个有难度的技术活,所以很多时候有心无力,也担心APP的后续的技术支持. ...
- 380. Insert Delete GetRandom O(1)
经过昨天的消沉 今天我振作了 设计个数据结构,添加,删除,随机获取都是O(1). 怎么会有这么牛逼的数据结构,所以肯定相应的要耗费空间. 添加和获取耗时O(1)是Array的特性,或者说是Map/Ta ...
- ar技术序章-SDK介绍和选择
转自: http://blog.csdn.net/kun1234567/article/details/10402535 ar技术序章-SDK介绍和选择 分类: Augmented Reality20 ...