没有OOP的封装是否可能? [英] Is encapsulation possible without OOP?

查看:101
本文介绍了没有OOP的封装是否可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一次采访中有人问我一个问题:如果没有OOP,封装是否可行?用程序语言吗?

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

推荐答案

鲍勃·马丁(Bob Martin)说,封装不仅在没有OOP的情况下是可能的,而且在OOP出现之前是更好的.一起.

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

这里摘录自谈话他于2014年在耶鲁大学管理学院就读.

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

我们有完美的封装.在C语言中,您所要做的就是向前声明函数和数据结构.您不必实施它们.您将在头文件中声明它们,然后在C文件中实现它们.您的用户将#include您的头文件.他们看不到您的执行情况.完美的封装.您的任何用户都无法看到您的任何数据值.他们只能看到您的功能签名.他们可以看到您数据结构的名称,但看不到您数据结构内的任何成员.绝对完美的封装.

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.

这篇关于没有OOP的封装是否可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆