何时/为何在课堂上将函数设为私有? [英] When/why to make function private in class?

查看:61
本文介绍了何时/为何在课堂上将函数设为私有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我什么时候应该创建函数private,为什么它是个好主意?

When should i make a function private and why is it good idea?

推荐答案

当您不需要其他对象或类来访问该函数时,应该从内部调用它,则应创建一个函数private.课.

You should make a function private when you don't need other objects or classes to access the function, when you'll be invoking it from within the class.

坚持最低特权原则,仅允许访问绝对必要的变量/函数.不符合此条件的任何内容都应为private.

Stick to the principle of least privilege, only allow access to variables/functions that are absolutely necessary. Anything that doesn't fit this criteria should be private.

这篇关于何时/为何在课堂上将函数设为私有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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