Object Oriented Programming
- It treats data as a critical element in program development and does not allow it to flow freely around the system.
- It ties data more closely to the functions that operate on it and protects it from accidental modification from outside functions.
- OOP allows decomposition of a problem into a number of entities called objects and then builds data and functions around these objects.
- The data of an object can be accessed only by the functions associated with that object.
- Functions of one object can access the functions of another object.
Organization of data and function in OOP
Characteristics of OOP
- Emphasis is on data rather than procedure.
- Programs are divided into objects.
- Data Structures are designed such that they characterize the objects.
- Functions that operate on data of an object are tied together in the data structure.
- Data is hidden and can not be accessed by external functions.
- Objects may communicate with each other through functions.
- New data and functions can be added easily whenever necessary.
- Follows bottom-up approach in program design.
Basic concepts of OOP
1.Classes
- Classes are user-defined data types
- A class is a collection of Data member and member functions.
- Variables declared in a class are called data members and functions declared in class are called member functions or methods.
- Objects are variables of type class. Once a class has been defined, we can create any number of objects belonging to that class.
- Each object is associated with the data of type class with which they are created.
- If Fruit is a class, then apple, orange, banana etc. are the objects of the class Fruit.
- Class is a logical structure.
2.Object
- Basic run-time entities in an object-oriented system i.e. fundamental building blocks for designing a software.
- It is a collection of data members and associated member functions(method).
- An object represents a particular instance of a class.
- An object has 3 characteristics:
- Name
- State
- Behavior
- Objects take up space in the memory and have associated addresses.
- When a program is executed, objects interact by sending messages to one another.
- Example : Book, Bank, Customer, Account etc.
3.Data Abstraction
- Abstraction refers to the act of representing essential features without including the background details or explanation.
- Data abstraction is an encapsulation of object’s state and behavior.
- Data abstraction increases the power of programming languages by creating user-defined data types.
- Classes use the concept of abstraction and are defined as a list of abstract attributes(data members) and functions(methods).
- Since classes use the concept of data abstraction, they are also used as Abstract Data Type(ADT).
4.Encapsulation
- Data encapsulation combines data and functions into a single unit
- called class.
- When using data encapsulation, data is not accessed directly, it is only accessible through the methods present inside the class.
- Data encapsulation enables data hiding, which is an important concept of OOP.
- Example : Capsules are wrapped with different medicines.
5.Inheritance
- It is the process by which one object can acquire the properties of another.
- It allows the declaration and implementation of new class/classes from existing classes.
- The existing class is known as base class/parent class/super class and the new class/classes is/are known as derived class/child class/sub class.
- It uses the concept of Reusability.
Types of Inheritance :
- Single Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
6.Polymorphism
- The ability to take more than one form is known as Polymorphism.
- An operation may exhibit different behaviors in different instances. The behavior depends upon the types of data used in the operation.
- + operator can be used to add 2 numbers and the result is the sum of two numbers.
- Same + operators can be used to add 2 strings and the result is concatenation of 2 strings.
- This process of making an operator to exhibit different behaviors in different instances is known as operator overloading.
Polymorphism (Function Overloading)
- A single function name can be used to handle different numbers and different types of arguments.
- Using a single function name to perform different types of tasks is known as function overloading.
7.Message Passing
- Any processing is accomplished by sending messages to objects.
- A message for an object is a request for execution of a procedure/function.
- It invokes a function on the receiving object that generates the desired result.
- Message passing involves specifying the name of the object, name of the function(message) and information to be sent.
Follow Us