re: PHP Typed Properties: Think Twice. VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Isn't the first example breaking the Encapsulation principle of OOP? I rarely ever use public properties, they are almost always protected or in so...
 
 

An excerpt from the article:

In the glossary of Design Patterns, Gamma et al., encapsulation is defined as "The result of hiding a representation and implementation in an object..."
So such luminaries as Gamma et al. and the designers of C++ (and Java) are wrong!?
Clearly that there are two definitions of encapsulation, but both valid. It's common for the same word to have different meanings in different communities or contexts. It is not meaningful to say one definition is correct and the other wrong.

 

You can call it however you want but if another object can directly (on properties) change the state of your object, that object is not encapsulated :)

code of conduct - report abuse