State & Status

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

State & Status_第1张图片

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。
State & Status_第2张图片

你可能感兴趣的:(java,java)