Saturday 25 August 2012

Object Oriented Programming

Object Oriented Programming as the name suggest is a programming technique which revolves around objects . In simple terms it is the process by which the real world problems are converted into software solutions . Let us take an example , tata safari is the real world object of class car , this object has two characteristics i.e it has a state(attribute or data)  and behavior (methods or functions).The state includes engaged gear , current speed etc and the behavior includes accelerations , changing gear , applying brakes etc . The software solution of the above will be attributes (data or state) and behavior (methods or functions) .
Attributes includes :   data : engaged_gear  type c,    (In ABAP)
                                             current_speed  type n.
                                   or
                                   int current_speed; (In Java)
Behaviors includes : method apply_brakes()
                                    {
                                        current_speed = current_speed - 2.
                                     }
                                    method accelerations() etc.
Following are the features of Object Oriented Programming

1.Class -  Class is a pattern or style based on which all the objects in that class is created . Class is a collection of attributes and behaviors of similar types of objects.
But a class does not have its physical existence it is the objects present in a class that have physical existence like the folders in our computer does not have physical existence rather it is the files that present inside the folder has physical existence i.e occupies some memory .
  • Attributes : Attributes contains the data that can be stored in the objects of a class.
  • Behaviors : Behaviors refers to the functionality of the object.
2.Object -  Object is the runtime instance of a class which has physical existence and having its own attributes and behaviors . We can create any number of objects based on a single class and the process of object creation is known as instantiation.

Example - Human is a class because we can not touch human i.e it does not have physical existence but we can touch the hands , nose , hair which are the objects of human class .
Car is a class because we can not touch car but we can touch indica car , safari car etc which are objects of class car.

3.Abstraction - Abstraction is a feature through which the essential parts of the object is represented hiding the background details.
  • Data is abstracted by high level language constructs such as numbers ,letters , high level data concepts etc.
  • Functionality is abstracted by presenting interfaces that hide complex logics such as methods or functions.
Example - When we are driving car we simply apply the brakes without knowing what is happening in the background that stop the car i.e unnecessary details are abstracted.

4.Encapsulation - Encapsulation is the packaging of attributes(data member) and behaviors(member functions) into one reusable module where user can only call certain functions or methods  but cannot access the data directly.This feature enables the class to hide the implementation details of the class.
It helps in data data hiding which leads to data security(making attributes and behaviors private) .

Example - Think of the capsules that doctor recomend you , which is nothing but the packaging of different benefitial drugs , leaves etc into one reusable module.

5.Polymorphism -  The term is derived from greek words poly means many and morphos means forms . So polymorphism means method having same name have different forms i.e objects from different classes react differently to the same method calls.

Example - Our behaviour is different when we are with our parents , different when we are with our friends , teachers etc . Similarly same method behaves differently based on which class object call it.

6.Inheritance -  Inheritance is the feature through which the attributes and behaviors of one object can be reused in other which leads to reusability and reusability leads to less amount of coding.

7.Exception Handling  -  Exception handling is a feature through which user can handle the abnormal behavior (number divided by 0 is an example of abnormal behaviour) of the programme . Whenever an exception , control navigates to the exception block handles the exception and exit out of the programme normally.

If you like this tutorial , please like and comment...