Clean Code: Should Objects have public properties?

前端 未结 13 1613
礼貌的吻别
礼貌的吻别 2021-01-03 20:40

I\'m reading the book \"Clean Code\" and am struggling with a concept. When discussing Objects and Data Structures, it states the following:

  • Objects hide thei
13条回答
  •  执念已碎
    2021-01-03 21:15

    Properties are essentially short hand for Getter and Setter methods. The point of Getter and Setter methods is to have the object handle any operations on variables so that you can do any extra operations (such as data-validation) without causing undesirably consequences.

    I think that you may be hung up on automatic properties, which have no backing variables and, as a result, look like variables themselves.

提交回复
热议问题