markdown [构建没有setter的对象模型] #design_pattern

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown [构建没有setter的对象模型] #design_pattern相关的知识,希望对你有一定的参考价值。

#### Some pointers

- Having setters violates open/close principle, prevents information hiding (breaks encapsulation)
- Discussing getter/setters vs public fields often obscures bigger problems with objects manipulating each others' internal state in an intimate manner and hence being too closely coupled. The idea is to make methods do what your business logic wants it to do, rather than have setters which change things at a field level.
- One way to avoid writing setters is a task based approach to the model. Think of every task that is performed in an application and add a method that changes all the affected fields at once, to perform this task.


Ref: 
- [Building an object model: No setters allowed](https://beberlei.de/2012/08/22/building_an_object_model__no_setters_allowed.html)
- [Are getters and setters poor design?](https://stackoverflow.com/questions/565095/are-getters-and-setters-poor-design-contradictory-advice-seen)

以上是关于markdown [构建没有setter的对象模型] #design_pattern的主要内容,如果未能解决你的问题,请参考以下文章

markdown 在Rails中构建富域模型(修订版2)

markdown getter,setter,프로퍼티#python #tutorial

markdown JS.Objects.classes.ES6getterand setter

AttributeError:'str'对象在构建逻辑回归模型时没有属性'decode'[重复]

没有为类型列表的JAX B对象生成Setter方法

没有默认构造函数的对象成员的 Swig setter