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

Why use Object-Oriented Programming?Why 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
Modularity Limited 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. High 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.
Reusability Low Procedural code tends to have low reusability, as it's often tightly coupled, making it less adaptable for reuse in various contexts. High 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.
Maintainability Challenging 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. Simplified 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:

code example

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:

code example

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:

code example

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.


1. Which programming paradigm typically allows for higher modularity and reusability of code?
2. How does object-oriented programming enhance the ease of maintaining code compared to procedural programming?
3. What is a key strength of procedural programming?

Which programming paradigm typically allows for higher modularity and reusability of code?

Selecciona la respuesta correcta

How does object-oriented programming enhance the ease of maintaining code compared to procedural programming?

Selecciona la respuesta correcta

What is a key strength of procedural programming?

Selecciona la respuesta correcta

¿Todo estuvo claro?

Sección 1. Capítulo 2

Why use Object-Oriented Programming?Why 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
Modularity Limited 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. High 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.
Reusability Low Procedural code tends to have low reusability, as it's often tightly coupled, making it less adaptable for reuse in various contexts. High 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.
Maintainability Challenging 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. Simplified 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:

code example

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:

code example

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:

code example

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.


1. Which programming paradigm typically allows for higher modularity and reusability of code?
2. How does object-oriented programming enhance the ease of maintaining code compared to procedural programming?
3. What is a key strength of procedural programming?

Which programming paradigm typically allows for higher modularity and reusability of code?

Selecciona la respuesta correcta

How does object-oriented programming enhance the ease of maintaining code compared to procedural programming?

Selecciona la respuesta correcta

What is a key strength of procedural programming?

Selecciona la respuesta correcta

¿Todo estuvo claro?

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