Sunday, August 2, 2009

What is object oriented programming and how does it relate to code reuse.?

I am learning how to do programming and I don't quit understand what object oriented programming is and how it relates to code reuse and what does code reuse means. Can someone tell me and give me some examples please.


Thank you

What is object oriented programming and how does it relate to code reuse.?
Perhaps you have to write a program that hadles users, stores their data into database, does some accounting calculations... You can write a program that consists of several parts - objects:





Object - User - with fields first name, last name, SSN...


Methods to set fields and to get fields.





Then you write Objects that use Object User say UserPayroll... calculate their income and such.





The implementation of User is separated from the User class,


in other words you can re-use the Object User in another application that will do different manupilations say write another object for ths - UserLogin or whatever - on Users - this is code re-use.
Reply:In object oriented programming the main emphasis is on the object. In 'C' langage(its not object oriented) the main emphasis is on code, object is given less importance. However in object oriented programming(like C++, java etc) object is given high importance.


Now coming to code re-usability, consider u write a program to add two numbers using methods. Now u need to write a program for all types of calculations say +,-,/,* now you can import the first program to the present program and by reusing the existing code u gain advantage of not writing the same code in different programs.

flower pictures

No comments:

Post a Comment