OOP stands for Object-Oriented Programming.
While procedural programming focuses on writing procedures or functions that operate on data, object-oriented programming revolves around creating objects that encapsulate both data and functions.
Object-oriented programming offers several advantages over procedural programming:
Tip: The “Don’t Repeat Yourself” (DRY) principle emphasizes minimizing code duplication. Extract common code into a single location and reuse it throughout your application rather than repeating it.
Classes and objects are the two fundamental components of object-oriented programming.
Refer to the following illustration to understand the distinction between classes and objects:
Class Fruit |
Objects Apple Banana Mango |
Here’s another example:
Class car |
Objects Volvo Audi Toyota |
A class serves as a blueprint for creating objects, while an object is an instance of a class.
When objects are instantiated, they inherit all properties and behaviors from the class, but each object can have distinct values for its properties.
Refer to the upcoming chapters to explore more about OOP.