Imumutable Object Posted on 2020-12-08 In Design Pattern , Concurrent Pattern 不可变对象及其作用通过使用不可变对象表征对象状态,避免访问状态时的同步需求。 所谓状态不可变,并非指现实世界的实体状态不可变,而是我们建模时的一种决策,即可以用不可变状态表示某时刻的状态,事物状态变化可以用替换为其他不可变对象表示。 Immutable Object 类图ClientManipulatorvoid changeStatusTo(int x, int y)ImmutableStatefinal int xfinal int yint getXint getYImmutableState( int x, int y)ImmutalbeState Sequence DiagramClientClientImmutableStateImmutableStateManulatorManulatornew ImmutableStategetStateXStateXgetStateYStateYchangeStatecreatenew ImmutableStategetState() Welcome to my other publishing channels RSS