当前位置:网站首页>成员函数和非成员函数
成员函数和非成员函数
2022-04-23 22:01:00 【稀缺-风险-谦逊】
成员函数:一个类里面定义地函数;
非成员函数:不是在类里面定义地函数;
那么是选择类的成员函数还是类的非成员函数呢?
面向对象则要求是,将操作数据的函数与数据放在一起。但这不意味着要选择成员函数。从封装的角度看,成员函数的moringAction封装性比非成员函数要低。如果某些东西被封装,它就不再可见。越多东西被封装,越少人可以看到它。所以使用非成员函数的类,封装性较低。而越少人看到它,我们就有越大弹性去变化它,因为我们的改变仅仅直接影响看到改变的那些人事物。因此,越多东西被封装,改变哪些东西能力越大。
在考虑对象内的数据。越少的代码可以看到数据(访问它),越多的数据可以被封装,而我们也就越能自由改变对象数据。现在如果一个成员函数、非成员函数都能提供相同的机能,我们选择非成员函数。
版权声明
本文为[稀缺-风险-谦逊]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zhou_z_p/article/details/124364960
边栏推荐
- [※ leetcode refers to offer 32 - II. Print binary tree II from top to bottom (simple)]
- Database Experiment 8 trigger experiment
- 21. Basic usage of MariaDB
- Detailed explanation of basic assembly instructions of x86 architecture
- Hystrix简介和服务端熔断的实现
- [leetcode sword finger offer 58 - I. flip word order (simple)]
- Introduction to hystrix and implementation of server fuse
- SSH in win10
- Yolov5 NMS source code understanding
- Strictly, severely and quickly strengthen food safety supervision during the epidemic in Shanghai
猜你喜欢
Ribbon 服务调用
[leetcode refers to offer 47. Maximum value of gift (medium)]
Handling of alternative solutions for openfeign integration with hystrix
[leetcode refers to offer 42. Maximum sum of continuous subarrays (simple)]
[leetcode refers to offer 52. The first common node of two linked lists (simple)]
[leetcode refers to offer 18. Delete the node of the linked list (simple)]
[leetcode sword finger offer 28. Symmetric binary tree (simple)]
NVM introduction, NVM download, installation and use (node version management)
Tsinghua University | webface260m: benchmark for million level deep face recognition (tpami2022)
Question brushing plan -- backtracking method (I)
随机推荐
The DNN of OpenCV is used to read onnx as the prediction end to realize classification
ERP function_ Financial management_ Basic concepts of Finance
Oracle ora-01033: Oracle initialization or shutdown in progressprocess solution
Hystrix简介和服务端熔断的实现
How Axure installs a catalog
Based on jsplumb JS to achieve multi list one to many connection effect
OpenFeign超时设置
Database Experiment 7 stored procedure experiment
服务间通信方式
降级和熔断总结
JS prototype and prototype chain
Leaf Smecta
consul 关闭健康监控检查
JUnit unit test ---- a good tool for testing a single method
Database Experiment 3 data update experiment
Ali has another "against the sky" container framework! This kubernetes advanced manual is too complete
延时消息常见实现方案
Question brushing plan -- backtracking method (I)
在线Excel转CSV工具
Problem brushing plan -- dynamic programming (IV)