Monday, December 8, 2014

Intro of OOPs

What is Procedure Oriented Programming Language?

In Procedure Oriented Programming Language, many instructions are written to carry out main task.
In this approach, main focus is on functions rather than data items.

Characteristics of Procedure Oriented Programming:-

  1. It uses top down approach.
  2. Functions share global data.
  3. Emphasis more on functions rather than data members.
Drawback of Procedure Oriented Programming:-

  1. As data member are globally shared by functions, if we do any changes in the values of data members then we may have to do necessary changes in functions too.
  2.  This approach is not suitable to solve complex problems in real life.
Advent of OOP:-

Terminology invoking "objects" and "oriented" came into existence in the late 1950s and early 1960s.
Object Oriented Programming is an approach to integrate code and data in terms of object that means it is a way to create partitioned memory area for both data and function. We can define it as "An Object Oriented Programming is an approach which allows data member to freely move in stipulated program area."

Characteristics of OOP:-
  1. It emphasis more on data members rather than functions.
  2. It decomposes complete problem into number of objects.
  3. The objects can be used as a bridge to convey data from one function to another function.
  4. We can easily modify data members and data function as per our requirement.

Differences between OOP and POP:-



Basic Elements of OOP:-


  • Objects
  • Classes
  • Data Abstraction
  • Encapsulation
  • Data Hiding
  • Inheritance
  • Polymorphism
  • Dynamic Binding

Objects:-Object is a unique entity, which contains data and functions together in OOP.

Class:- Class is a blueprint or template or factory that  describes the nature of an object.

Let's understand with an example, if we talk about a bird, wings, legs, color, beak etc features come in our mind. A real entity in which we can see all these characteristics we call it as bird.That means, we can say Parrot is an object of Bird class as it has all the characteristics of a Bird. Few more examples are as below:-

Car------>Nano, Maruti etc
Student------>Jane, Jack, Susan etc
Flower------->Jasmine,Rose etc

How can we create Object of a Class in JAVA?


There are three steps:
1)Declaration :- In this step we declare object as class its object.
2)Instantiation:- new key word is used for dynamic memory allocation.
3)Initialization:- Constructor is called for attribute initialization of an Object.

Syntax:- Class_Name Object_Name= new(operator) Constructor();

Bird=====>Class,means blue print.
Parrot===>Object,means instance of Bird Class.
new====>new Operator is used for dynamic or runtime allocation of memory for the storage of data and function belonging to an object.
Constructor====>Special type of function, we will talk about it in dealt in our subsequent topics, for the moment beginners I would like to say name of class and constructor is same.

Data Abstraction:- Providing relevant or required information.
In our real life situation, we are not required to know the details of technology to operate any device. For eg, We can give call,send messages, click images ,listen songs etc with our cell phone. But what is mechanism behind it, only one answer comes that is simply NO. That means, it simply implies if you want to operate your cell phone you are required to know only it essential feature and not the mechanism behind it. Thus, we can say , abstraction is an act of representing essential features without including background details.

How can we say class has abstraction property?
The class encapsulates the data items and the functions. The data members are accessed only through the related functions. In this way class uses the property of abstraction and hence also know as Abstract Data Type(ADTs).

Inheritance:- This term is derived from biology, the literal meaning is acquire features.In OOP, object of a class can acquire characteristics from object of other class. That means, we can define inheritance is a process in which object of a class can link and share common properties from object of other class. The process of re-usability can be easily attained if a class inherits another class.


Polymorphism:-"Available in many forms" is its literal meaning.To understand this, let's take an example of a lady who behaves like a mother for her kid, behaves like a wife for her husband, and senior executive in her office. Her interface is same but her behavior is different in different aspects of life. 

Dynamic Binding:- It is an approach to establish link between function call and function singnature during run time. The mechanism is explained below:=


In the above figure, compiler has generated code address of function calculate and replaced it in the caller program at call position. During execution of the caller program control gets transferred to the required address to invoke the Calculate function.  


Benefits of OOPs:-

  1. Re usability  can be attained using inheritance.
  2. Data Hiding concept can generate secure program.
  3. Multiple objects can exits without any interference.
  4. It is highly beneficial to solve complex problems.