O'Reilly logo
  • LI WEI thinks this is interesting:

The argument for using mutator methods is to write additional code before the assignment of a variable to guard the variable from taking on incorrect values. Say, for example, we have a setter for the hp data member, which will look like this:

From

Cover of Learning C++ by Creating Games with UE4

Note

写成set函数和我们前面设置血量的概念一样,方便将来对算法进行扩充