Is encapsulation possible without OOP?

放肆的年华 提交于 2019-12-24 08:09:15

问题


I was asked a question in an interview: if encapsulation is possible without OOP, e.g. in a procedural language?


回答1:


Bob Martin has stated that encapsulation is not only possible without OOP, it was better before OOP came along.

Here is an excerpt from a talk he gave in 2014 at Yale School of Management.

We had perfect encapsulation. In C, all you had to do was forward declare your functions and your data structures. You didn't have to implement them. You would forward declare them in a header file, and then you would implement them in a C file. Your users would #include your header file. They could see nothing of your implementation. Perfect encapaulation. There was no way any of your users could see any of your data values. All they could see was your function signatures. They could see the names of your data structures but none of the members inside your data structures. Absolutely perfect encapsulation.



来源:https://stackoverflow.com/questions/52645937/is-encapsulation-possible-without-oop

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