C++ Object-Oriented Programming

Object-Oriented Programming is one of the ways to manage the complexity of programming. The machine and assembly language were not highly suitable for very complex programs. Then, came high-level procedural languages such as FORTRAN, BASICS, PASCAL and C. This Procedural approach to programming has worked well, however, the complexity of software is ever increasing with more powerful computer hardware. This complexity has forced the programmers to adopt a new programming paradigm: the object oriented programming(OOP)

The Object-Oriented Programming is a new way of organizing, combining both data and the associated functions into a single unit called class. Object Oriented Programming systems (OOPs) is an approach to program organization and development that provides a way of modularizing a program by creating partitioned memory area for both data & function that can be used as templates in another program.

Object-Oriented Programming allow programmers to build large programs with clarity, extensibility and easy to maintain.

Concepts of Object-Oriented Programming

  1. Objects: Objects are the runtime entities in an Object-Oriented System. They may represent a person, a place, a bank account, a table of data etc.
  2. Classes: A Class is a User-Defined data type in which we can define different data items and functions. Objects are the variables of type class. Once a class has been defined, we can create any number of objects belong to that class. Thus, a class is a collection of similar type of object.
  3. Data Encapsulation: The wrapping up of data and functions into a single class is known as Encapsulation. Using Encapsulation, we can limit the accessibility of data and functions which are wrapped in the class to the outside world.
  4. Data Abstraction and Hiding: Abstraction refers to the act of representing an essential feature without including the background details or explanations. The technique of hiding internal/unwanted information in an object is called data abstraction. The main advantage of abstraction is that a user can use an object without knowing all its details.
    In C++, classes can be defined in which the data can be specified as Private. The Private data can be accessed only by the member functions of the class.
  5. Inheritance: Inheritance is the process by which objects of one class acquires the properties of another class. A derived class inherits all the attributes and behavior of the base class and may have additional ones as well. Inheritance provides re-usability feature. This means that we can add additional features to an existing class without modifying it.
    Types of Inheritance:
    a. Single inheritance: Properties of one class are inherited in only one derived class.
    b. Multiple inheritance: Many classes inherit the property in one class.
    c. Multi-level inheritance: One class inherits property in the other class, and that class inherits the property in another subclass.
    d. Hybrid inheritance: It is a combination of Multiple and Multilevel inheritance.
    e. Hierarchical inheritance: when the properties of one class are inherited by more than one class, it is called hierarchical inheritance.
  6. Polymorphism: Polymorphism means one name multiple forms. Polymorphism is a Greek word which means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends upon the types of data used in the operation. Polymorphism is of 2 types:
    a. Compile time polymorphism: when the information is known to the compiler during compile time is known as compile time polymorphism. Types of compile time polymorphism are:
    1. Function overloading
    2. Operator overloading
    b. Run time polymorphism: when the information is not known to the compiler during compile time is known as run time polymorphism. Types of run time polymorphism.
    1. Virtual function
  7. Data Binding: There are 2 types of Binding
    a. Static Binding: when the information is known to the compiler at compile time, it is known as early binding or static binding or static linking. For example, function and operator overloading. In overloading, compiler knows the information at the compile time and able to select the appropriate function for a particular call at compile time.
    b. Dynamic Binding: It is also known as late binding. In Dynamic Binding, the code is associated with a given procedure call is not known until the time of call at runtime. For example, Virtual Function. Dynamic Binding requires use of pointers to objects.

Advantages of OOP's

The following are the basic advantages of object-oriented programming systems:

  1. Reusable: Objects once made can be reused in more than one program. This is a time-saving and quality improvement mechanism that adds coding efficiency to a language.
  2. Modular Design: Any complex program can be divided into modules. So that software complexity can be easily managed.
  3. Extensible: Object-Oriented system can be easily upgraded from small to large systems.
  4. Redundancy: Using Inheritance, we can remove redundancy.
  5. Secure: The principle of data hiding helps the programmer to build secure programs.
  6. Maintainable: using oops concept we can easily add, update or remove any component in a program.