Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Why use Object-Oriented Programming? | Fundamentals of OOP
C++ OOP
course content

Contenido del Curso

C++ OOP

C++ OOP

1. Fundamentals of OOP
2. Constructors and Destructors
3. Encapsulation Overview
4. Inheritance Overview
5. Polymorphism Overview

bookWhy use Object-Oriented Programming?

It is quite simple to create a comparison between Procedural programming and Object-Oriented Programming (OOP). To grasp this comparison better, let's delve into the key characteristics of each approach:

Procedural
OOP
ModularityLimitedHigh
In procedural programming, modularity is somewhat limited, as code is organized into functions or procedures but may not always be neatly encapsulated or shareable across different parts of a program.In Object-Oriented Programming (OOP), modularity is high due to the use of classes and objects, which encapsulate data and behavior together, making it easier to manage and understand complex systems.
ReusabilityLowHigh
Procedural code tends to have low reusability, as it's often tightly coupled, making it less adaptable for reuse in various contexts.In OOP, reusability is high because objects can be instantiated from classes, facilitating code reuse in various parts of an application, which promotes consistency and reduces the chances of errors.
MaintainabilityChallengingSimplified
In procedural programming, maintainability can be challenging as programs grow in complexity. It becomes harder to keep track of all the procedures and their interdependencies, making debugging and making changes more complex.OOP simplifies maintainability due to its clear structure and encapsulation. Changes and updates can often be localized to specific classes or objects, reducing the risk of unintended side effects in other parts of the codebase.

Why it is important to bundle data

Consider the task of developing a software application for managing students' data, it might seem straightforward at first. For example, you could start with a simple structure to store a student's name and their grade point average (gpa). Here's a basic illustration:

This approach is fine when dealing with a single student. However, complexities arise when you want to manage multiple students. A naive approach might involve creating separate variables for each student:

This method quickly becomes unmanageable as the number of students increases. Using arrays can help reduce repetition, but what if you need to expand the data you store for each student? Let's say you want to add email addresses:

The solution to these issues lies in Object-Oriented Programming (OOP) because it allows you to create a Student class, a blueprint for student objects. It can store all the relevant information (like name, gpa, and email) and behaviors of a student.

Note

While you can use struct to achive similar goals, it cannot fully replace Object-Oriented Programming. We will dive into a more comprehensive explanation of this distinction later in the course.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 2
some-alt