Object-Oriented Programming is centered on new concepts such as classes, polymorphism, inheritance, etc. It is a well suited paradigm for the following:
- Modeling the real world problem as close as possible to the perspective of the user.
- Interacting easily with computational environment using familiar metaphors
- Constructing reusable software components and easily extendable libraries.
- Easily modifying and extending implementations of components without having to recode everything from scratch.
Definition of OOP:
OOP uses objects as its fundamental building blocks. Each object is an instance of some class. Classes allow the mechanism of data abstraction for creating new data types. Inheritance allows building of new classes from existing classes. Hence if any of these elements are missing in a program we cannot consider that program as objected oriented program.
Object-oriented programming is a programming methodology that associates data structures with a set of operators which act upon it. In OOP’s terminology an instance of such an entity is known as an object. It gives importance to relationships between objects rather than implementation details. Hiding the implementation details within an object results in the user being more concerned with an objects relationship to the rest of the system, than the implementation of the object’s behavior.
Objects:
Objects are the basic run-time entities in an object-oriented system. Every object is associated with data and functions which define meaningful operations on that object.
What is Encapsulation:
It is a mechanism that associates the code and the data it manipulates into a single unit to and keeps them safe from external interference and misuse. In C++ this is supported by construct called class. An instance of a class is known as an object which represents a real world entity.
What is Data Abstraction:
A data abstraction is a simplified view of an object that includes only features one is interested in while hides away the unnecessary details. In programming languages, a data abstraction becomes an abstract data type or a user-defined type. In OOP, it is implemented as a class.
What is Inheritance:
Inheritance is a means of specifying hierarchical relationships between types C++ classes can inherit both data and function members from other (parent) classes. Terminology: “the child (or derived) class inherits (or is derived from) the parent (or base) class”.
What is Polymorphism:
Polymorphism is in short the ability to create a variable, a function, or an object that has more than one form. It is a lot useful since it can group classes and their functions together. Polymorphism means that the same thing can exist in two forms. This is an important characteristic of true object oriented design – which means that one could develop good OO design with data abstraction and inheritance, but the real power of object oriented design seems to surface when polymorphism is used.
What is Message passing:
It is the process of invoking an operation on an object. In response to a message the corresponding method is executed in the object.
What is Extensibility:
C++ allows the extension of the functionality of the existing software components. In C++ this is achieved through abstract classes and inheritance.
What is Persistence:
The phenomenon where the object (data) outlives the program execution time and exists between executions of a program is known as persistence. All data base systems support persistence. In C++ it is not supported. However the user can build it explicitly using file streams in a program.
What is Delegation:
Delegation is a way of making object composition as powerful as inheritance. In delegation two objects are involved in handling a request receiving object delegates operations to its delegate. This is analogous to child class sending requests to the parent class.
What is Genericity:
It is technique for defining software components that have more than one interpretation depending on the data type of parameters. Thus it allows the declaration of data items without specifying their exact data type.
What is Multiple Inheritance:
The mechanism by which a class is derived from more than one base class is known as multiple inheritance. Instances of classes with multiple inheritance have instance variables for each of the inherited base classes. C++ supports multiple inheritance.
In the next chapter, we will discuss how programmer can change from C style of programming to C++ style without temporarily bothering about C++ object-oriented features. Mastering the concepts of C++ without the OOP concepts bolsters the confidence of the learner. Even if the learner does not want the OOP concepts he has many features used in C made better and more powerful in C++.