DEV Community

Discussion on: Writing value objects in PHP

Collapse
 
ianrodrigues profile image
Ian Rodrigues

Yes, that is part of OO principles.

Collapse
 
mtamazlicaru profile image
Marius Tamazlicaru

Hi, thanks for the article. Could you please specify what OO principle is this?

Thread Thread
 
ianrodrigues profile image
Ian Rodrigues

Hi @mtamazlicaru, sorry for the very late response. I've been away from dev.to for a while.

This behavior is part of the encapsulation principle in object-oriented programming. Encapsulation is about keeping a class's internal data and implementation details 'enclosed' within the class, and only exposing a public interface to the outside world.

However, a unique aspect of this principle is that in many programming languages, two instances of the same class can access each other's private methods and properties. This is because the class itself is considered the boundary of encapsulation, not the individual instances.

So, when two objects are of the same class, they are allowed to see each other's private parts, so to speak. This feature can be quite useful in certain scenarios, like implementing methods that compare two objects of the same class. Hope this helps clarify things!