If I'm the only developer on a project, do I still need to use encapsulation? [closed]

扶醉桌前 提交于 2019-12-24 16:43:09

问题


I always hear that we need to encapsulate whenever we write object-oriented code. If I'm the only developer on a project, do I still need to use encapsulation?


回答1:


One way to put an answer: Encapsulation, conceptually, exists for writing better, safer, less error-prone code. It doesn't exist, primarily, to facilitate teams working together on code (that might be a side effect, but that's not the purpose).

So the goods that encapsulation seeks to foster scale from one coder to many coders, and they are goods that do not really have to do with the number of coders, although those goods may find stronger expression the larger the project and teams are.




回答2:


Encapsulation is there for a reason.

Someone has to maintain and manage your code after you are done, right? What if the project gets bigger and you get team members?

So, the answer is "yes", it is always best to use encapsulation whenever possible.




回答3:


The fact you are asking this question makes me wonder you actually did not get the actual value of encapsulation as a means to reduce and thus deal with complexity. My theoretical computer science professor used to tell me that in the end, if you think at the whole binary representation of a program, any program is just a number. Very big indeed but, only a number. And that is true, any other construct we use but 0 and 1 (i.e. C++, Java, Python, functional programming, object oriented programming, aspect oriented programming, etc..) is just because of the fact we need more abstract means to get the one number we need.



来源:https://stackoverflow.com/questions/14252084/if-im-the-only-developer-on-a-project-do-i-still-need-to-use-encapsulation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!