php:为什么我们需要设置类成员的可见性? [关闭]
问题描述:
I know, by using protected or private, we can limit the visibility of a member in a class. But I'm curious about the purpose of doing so. Calling a class name($a = new class B
) doesn't make its members global. So, why still need to protect its members?
我知道,通过使用protected或private,我们可以限制类中成员的可见性。 但我很好奇这样做的目的。 调用类名( $ a = new class B code>)不会使其成员成为全局。 那么,为什么还需要保护其成员? p>
div>
答
For low coupling and high cohesion
Please check below:
http://www.hokstad.com/why-coupling-is-always-bad-cohesion-vs-coupling