Wednesday, 16 September 2015

Why use object oriented programming


Before object oriented programming there was procedural c++ language which just contain some collection of function and some data in the form  of global and local variables. Object oriented programming is used widely because it is helpful in many occasions,it provides us with a mechanism of class by using which we can instantiate objects which use the properties of class.Now consider that you have a situation where you have to program on the 100 students.Will you write functions and data members for each of the student? just think for a moment? Of course no this will increase the length of program by manifold and it will create a lot of problem in debugging  and it will become difficult for a programmer to just manage the whole program. Oop in c++ provides a best solution to solve this problem,by using oop you can put common things between objects in a class and then whenever u have to use the class you only instantiate a object from that class.
Object oriented programming is used to increase the reusability byusing concept of inheritance which i will explain at some later time.First let as see how it increase the reusability .Lets suppose  you make a soccer game in which there are 4 different classes namely :

    (1)   ground
    (2)  weather
    (3)  audience
    (4)  player

now you at some latter time make a basketball game and you have the requirement to use weather and audience .would not it been better to use the classes we have already made in previous games like soccer game or we should write  separate classes for that game.

  Object oriented programming also help to maintain and modify the code for example just consider for a moment that your client ask you to modify the software you made for him.Suppose that your client asked you to make a employee database which should contain following information about employee:

 (1) First name
 (2) Last name
 (3) Cnic No
 (4) Pay

 Suppose that after some time your client asks you to replace cnic no with the age in employee database. It will become impossible for a  programmer to solve this issue without creating more problems. Modification of data is very difficult in c++ procedural programming so we use object oriented programming to avoid problem of mismanagement in code.Object oriented programming helps the programmer to modify and management the code quite easily.


Last but not least,object oriented programming made it easier to understand coding.





0 comments:

Post a Comment

Popular Posts