DEV Community

Discussion on: PHP Typed Properties: Think Twice.

Collapse
 
blackcat_dev profile image
Sasha Blagojevic

Isn't the first example breaking the Encapsulation principle of OOP? I rarely ever use public properties, they are almost always protected or in some cases private.

I'd put these interfaced properties that you propose in Abstract classes rather than in Interfaces. Makes more sense in my opinion, Interfaces should stay stateless and remain the messaging contract. :)

Collapse
 
kip13 profile image
kip
Collapse
 
blackcat_dev profile image
Sasha Blagojevic

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 :)