What is OOP? Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or objects , rather than functions and logic.
Class Class is comparable to an object’s blueprint.
Objects Object is an element (or instance) of a class; objects have the behaviors of their class.
Four (4) pillars of OOP
Encapsulation Encapsulation means containing all important information inside an object, and only exposing selected information to the outside world. This principle hides the internal software code implementation inside a class and hides internal data inside of objects. Encapsulation requires defining some fields as private or public .
Abstraction Abstraction means that the user only interacts with selected attributes and methods of an object. It uses simple things to represent complexity, the main goal is to hide complexity details from the user.
Inheritance Inheritance is one of the most important aspects of OOP. It allows classes to inherit features of other classes. Put another way, parent classes extend attributes and behaviors to child classes. Inheritance supports reusability .
Polymorphism Polymorphism literally means “many forms” . This principle focuses on designing objects to share behaviors. Building from inheritance, polymorphism allows the same method to execute different behaviors in two ways: method overriding and method overloading.
Advantages of OOP
1. Enables code reusability The idea of inheritance is one of the critical concepts offered by object-oriented programming. A class’s attributes can be passed down through inheritance, eliminating the need for duplication of effort. Doing this prevents the problems associated with repeatedly writing the same code.
2. Increases productivity in software development We can create programs from pre-written, interconnected modules rather than having to start from scratch, which would save time and increase productivity. Thanks to the OOP language, we can break the software into manageable, discrete problems. Because it allows for the division of labor in the creation of object-based programs, object-oriented programming is modular.
3. Makes troubleshooting simpler When object-oriented programming is used, troubleshooting is made simpler since the user knows where to look in the code to find the source of the problem. Since the error will indicate where the issue is, there is no need to inspect additional code areas.
4. Reinforces security We can create programs from pre-written, interconnected modules rather than having to start from scratch, which would save time and increase productivity. Thanks to the OOP language, we can break the software into manageable, discrete problems. Because it allows for the division of labor in the creation of object-based programs, object-oriented programming is modular.
5. Provides design advantages A significant development in software engineering has been object-oriented development. Among other things, it promises to shorten development duration and give firms a competitive advantage.
Lab. Activity 2 Convert Activity 1 problem 9 to OOP paradigm