Wednesday, 29 August 2012

What is Object Oriented Programming or What is the use of Object Oriented programming?


With the Object Oriented programming language, the programmer can relate the programming to the real world and it helps in breaking the  complex problems to small chunks thus making the program more efficient.

Let us examine this with a basic example.I just want to show how the Object oriented approach makes the programming easy and helps to break the complex problem in to small chunks in the real world and also in the programming Language.

Ex: Programming to represent 'A School'

If the requirement was to design a software which represents a School, we will see how we start up this with the Object oriented Approach.

Everything is treated as an object in the Object Oriented Approach. There are tree main steps involved in the Object oriented approach.

1) Identify different type of Objects
2) Define the state and behavior of each object
3) Define the Object Interaction.


1) Identify the objects that are present in a School

Everything that we see as an entity in a school can be said as object.Some of the objects in a school can be:

Students, ClassRoom, Chairs, Progress Cards, Examinations, Teachers, Principal,Infrastructure, Accountant

There will be lot more objects involved in a school.But to keep it simple, let us limit to the above list.

2) Define the state and behavior of the objects.

State- Tells about the current position of the object. It tells about the properties that are measurable or can be defined.For Example a Student's state will contain his name, ID number, standard, grade,Address

Behavior- The Behavior of any object is the work that particular Object can do.For the same Student Object, the behavior will be "Study", "Play","Go to Home","Come to School","Do Homework"

In the same way let us try to define the state and behavior of all the objects specified in Step 1


Object
State
Behaviour
Students
Name, ID number, Standard, Grade, Address, School Name
"Study", "Play", "Go to Home", "Come to School", "Do Homework", “Give tests”
Class Room
Location, Class Room ID number, Height, Width, Length of the room, Number of students it can accommodate, for which Standard?, in which School?
No Behaviour
Chairs
Model, Make, Colour, Height, located in which class?
No Behaviour
Teachers
Name, Address, Id Number, Subject
Teaches any subject to Students, Give Homework, Verify Homework, Conducts tests
Principal
Name, Address,
Talk to teachers, Manage, Check the quality of education
School
Name, Location



Given the above information, with the object oriented approach, we first build each object.
Create the following
-          School Object
-          Principal Object which have reference to School Object
-          Teacher Object which have reference to Principal Object
-          Student Object  
-          Chair Object
-          Class Room Object containing Multiple Chair Objects
3) Once we create the above objects we can make the objects interact with one another
Like, the Principal object interacting with the teacher object, the teacher object interacting with student objects and so on.

If you observe,In steps 1 and 2,  we made the whole concept simple.Instead of directly programming for a school which sounds complex, we started programming for smaller chunks(Students, Principal, Teacher and so on) and later make these objects interact with one another.


In Other words, first the objects are being made and then they are allowed to interact with each other. This is what a typical Object Oriented programming is. By doing the above breakup and treating everything as an object, it helps one understand and analyse the complex real time problems.

The Object oriented approach has different concepts called as OOPS concepts like encapsulation, inheritance, polymorphism which decorates the above said Object oriented approach and making it more secure, flexible, extensible and usable.









No comments:

Post a Comment