Introduction to OOP OOP stands for Object-Oriented Programming . Procedural programming is about writing procedures or functions that perform operations on the data, while object-oriented programming is about creating objects that contain both data and functions. Definition: Object oriented programming is a programming methodology that associates data structures with a set of operators which act upon it.
Elements of OOP • Objects • Classes • Encapsulation • Data Abstraction • Inheritance • Polymorphism • Dynamic Binding • Message Passing
Object: This is the basic unit of object oriented programming. That is both data and function that operate on data are bundled as a unit called as object. Class : A class is a user defined data type. It serves as a template of the objects. It includes data and the member functions that operate on data.
Encapsulation : The wrapping up of data and member function into an object is called encapsulation. The data is not accessible to the outside world and only those functions which are wrapped into the object can access it. Data Abstraction: Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details. ”“Data abstraction becomes an abstract data type (ADT)or a user-defined type.”
Inheritance: Inheritance is the mechanism to provides the power of reusability and extendibility. Inheritance is the process by which one object can acquire the properties of another object. Polymorphism : Polymorphism enables one common interface for many implementations, and for objects to act differently under different circumstances. You can also achieve polymorphism in C++ by function overloading, operator overloading and implementation inheritance.
Dynamic Binding: In dynamic binding, the code to be executed in response to function call is decided at runtime. C++ has virtual functions to support this. Message Passing: Objects communicate with one another by sending and receiving information to each other. Message passing involves specifying the name of the object, the name of the function and the information to be sent.