Previous: Constructors & Destructors

One of the four pillars of OOP: abstraction, encapsulation, inheritance, and polymorphism.

Data Encapsulation is simply the data and the methods related to one another that are encapsulated as classes so that the management is simple and convenient.

Different members of a class:

Properties can define get and/or set methods, also known as getters and setters. Setters allow you to control how values are set to protected instance attributes, that is, these methods are used to change the values of underlying instance attributes. Getters allow you to control how values are returned. Getters don't change the values of the underlying attributes.

Events allow instances to notify other objects when an event takes place. A publisher instance raises or sends an event, whereas a subscriber instance receives or handles the event. Instances can subscribe to events to add the necessary code to be executed when an event is raised, that is, when something of interest occurs.

It's also possible to define methods that don't require an instance of a specific class to be called; therefore, you can invoke them by specifying the class name and the method name. These methods are known as class methods. For example, ClassName.methodName(). They operate on a class as a whole and have access to class fields, but they don't have access to any instance members (such as instance fields, properties, or methods) because there is no instance at all.