State & Status

在开发的过程中总需要给变量起名,status和state哪个用来表示状态?有啥区别?总是很难分清楚,最近从网上搜了一下,没有发现本质区别,只是使用方式上的不同:

status:在做状态讲时侧重 进展,情形;

state:在做状态讲时范围比较广,指一般的状态,情况。 

以下来自网络:

status: a situation at a particular time, especially in an argument, discussion etc.

state: the physical or mental condition that someone or something is in

A hotel room might have a status of standard, de-luxe or honeymoon-suite. That same room may have a state of being dishevelled or clean.

A project progresses through a series of predefined stages. Its status tells you where it is in that series. Its state might be in disarray or on target regardless of status.

In considering this I asked myself two questions: What is the status of X? What sort of state is X in?

In reality, I suspect there is considerable overlap in the usage of state and status.

State 表达的是形态,而 Status 表达的是从一种形态转换成另一种形态的过程中,那些有显著特征的离散中间值。

举一个旅馆房间的例子,一个房间可以是婚房、普通房、豪华总统房,这些都是用 State 来表达。把一个普通房改造成豪华总统房,这个过程就有设计、材料准备、工人就位、施工、验收等步骤,这个时候就用 Status 来表达。那么,区分点在哪?区分点就在于一个房间当用 State 描述时,它是个彼此独立的枚举值,可以没有前后顺序的在婚房、普通房、豪华总统房之间来回转换。而当使用 Status 时,是存在前后状态依赖关系的一个变化量,不能没有做设计就施工,也不能没施工就验收。 

所以,State 和 Status 的核心区别,就是它们的枚举值之间是否有依赖关系,没有依赖关系的用 State,有依赖关系的用 Status。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值