It is necessary to understand some concepts used extensively in object-oriented programming.
- Objects
- Classes
- Data abstraction and encapsulation
- Inheritance
- Polymorphism
- Dynamic binding
- Message passing
Object
Objects are the basis run time entities in the object oriented system.They may represent a person, a place,a bank account and any item that program has to handle.They may also represent a user-defined data such as lists and time.Program objects should be chosen such that they match closely with the real-world objects.Object take up space in memory and have associated address like a record in pascal,or a structure in c.
When a program is executed,the objects interact by sending messages to one other.For example if "customer" and "account" are two objects in a program then the customer object may send a message to the account object requesting for the bank balance.Each object contains data and code to manipulate the data.Objects ca interact without having to know details of each other's data or code.It is sufficient to know the type of message accepted, and the type of response returned by the objects.
Class
A class is a collection of same type of objects having same attributes and common behaviours.It is just template or blueprint to create object.
Consider an example of an object you.Now you certain attributes like your age ,name,height etc and certain behaviours like you have some style like walking,speaking.Similarly your friends Rajveer , Sukdav, Amit also certain attributes like age,name,height etc and certain behaviours like walking,speaking.All these people represents different objects having same attributes and common behaviours.So all these objects can be grouped together a class person.
Class person
age (attributes)
name (attributes)
height (attributes)
walking() (Functions)
speaking() (Functions)
objects:-You(person),Rajveer(person),Sukdav(person),Amit(person)
Data Abstraction and Encapsulation
The wrapping up of data and functions into a single unit is known as encapsulation.Data encapsulation is the most striking feature if a class.The data is not accessible to the outside world,and only those functions which are wrapped in the class access it.The functions provide the interface between the objects's data and the program.This insulation of the data from direct access by the program is called data hiding.
Abstraction is process that involves the identification essential features without knowing the internal detail of a function.Abstraction mange complexity of a program.Classes use the concept of abstraction and are defined as a list of abstract attributes such as size,weight and cost and functions to operate on these attributes.
Since the classes use the concept of data abstraction,they are know as Abstract Data Types (ADT).
Inheritance
Inheritance is process of driving new class from an existing class without modify itThis is known as derived class,Sub class,Child class.
In OPP,the concept of inheritance provides the idea of reusability.This means that we can add additional features to an existing class without modifying it.This is possible by deriving a new class from the existing class.The new class will have the combined features of the both the classes.
Polymorphism
Polymorphism is av very powerful concept that allows the designing of amazingly flexible applications.The word Polymorphism is derived from two Greek words Poly which means many and morphos which means forms.So,Polymorphism means the ability to take many forms.
Polymorphism can be defined as ability to use the same name for two or more related but technically different tasks.In other words,Polymorphism can be defined as one interface that can be used to perform related but different tasks.For example,in C language to perform the addition of two integers or floating point numbers we need three separate functions (like sum_int(),sum_float()) for performing these two tasks.This is because C language does not support Polymorphism.But in case of C++ which supports Polymorphism,each function can be called by the same name such as sum().
Dynamic binding
Binding refer to the linking of a function call to the code of the function to be executed in response to the function call.
Binding is of two types
a) Static Binding :- In Static Binding, the linking of a function call to the code of the function to be executed in response to the function call is made at the compile time.
b) Dynamic Binding :-In Dynamic Binding, the linking of a function call to the code of the function to be executed in response to the function call is made at the run time.
Message passing
In Object Oriented Programming (OOP) different objects communicate with each other using the concept of message passing.Objects communicate with one other by sending and receiving informination much the same way as people pass messages to one another.The concept of message passing makes it easier to talk about building systems that directly model or simulate their real-world counterparts
Advantages of OOPs
- Data Security (Data Hinding & Abstraction)
- Improve Maintaiance & Modification
- Reusability
- OOPs is well suitable for Modelling Real word problem.
- Reduce complexity
- OOPs provide the facility of creating multiple objects of a class.
- Easy to locate and remove bugs and error.
Comments
Post a Comment