Читать книгу PHP This! A Beginners Guide to Learning Object Oriented PHP - Michelle Gosney - Страница 13

Encapsulation

Оглавление

Encapsulation means what the term implies, to put in a “capsule,” to place functionality into a single package. Consider an object as a capsule or a box that has things in it. The access modifiers are like windows that control who gets to see inside with ‘public’ access being a wide open window that let's everyone see inside and ‘private’ access being fully shaded that doesn't let anyone see inside.

The control over the visibility of the contents of an object is a big part of how encapsulation works.

The contents of an object are properties and methods and because they are all packaged inside an object they make up a sort of mini-program that has control over how visible its contents, data, are. This is encapsulation.

Technically speaking, encapsulation refers to the creation of self-contained modules that bind processing functions to the data. Encapsulation ensures good code modularity, which keeps routines separate and less prone to conflict with each other. To reiterate, you can think of each object as a mini program that handles it’s own responsibilities as it’s own self contained capsule or pill.

PHP This! A Beginners Guide to Learning Object Oriented  PHP

Подняться наверх