Structured programming only deals with procedures (functions) and variables. The basic idea behind the Object Oriented Programming is that it deals with the objects. In real life everything is an object and every object has properties and functionality.
As everything in the computer world is derived from the real life, like online books resemble with original hard binded books, the computer screen has more width than height as when we open a book its width is more than its height. So there was a need to make the computer programs more near to the reality. Object Oriented Programming is much nearer to the real world. In the reality everything is an object, it has some properties and do some functionality, inherits some functionality from others etc…
What is an Object?
Objects are the basic run-time entities in an Object Oriented System. They may represent a person, a place, a bank account, a table of data or any item that the program must handle. They may also represent user defined data such as vectors, time and lists.
Programming problem is analyzed in terms of objects and the nature of communication between them. Program objects should be chosen such that they match closely with the real-world objects.
When a program is executed, the objects interact by sending massage to one another. For example, if “customer” and “account” are two objects in a program, then the customer object may send a message to the account object requesting for the bank balance, Each object contains data and code to manipulate the data. Object can interact without having to know details of each other’s data or code. It is sufficient to know the ” of massage accepted and the type of response returned by the objects.
Example of an Object
Lets take the example of vehicle and make an its object and use it to print the properties of that object..
class vehicle { protected: int wheels; float weight; public: void initialize(int in_wheels, float in_weight); int get_wheels(void) {return wheels;} float get_weight(void) {return weight;} float wheel_loading(void) {return weight/wheels;} }; main() { vehicle unicycle; unicycle.initialize(1, 12.5); cout << "The unicycle has " << unicycle.get_wheels() << " wheel.n"; cout << "The unicycle's wheel loading is " << unicycle.wheel_loading() << " pounds on the single tire.n"; cout << "The unicycle weighs " << unicycle.get_weight() << " pounds.nn"; } // initialize to any data desired void vehicle::initialize(int in_wheels, float in_weight) { wheels = in_wheels; weight = in_weight; } // Result of execution // // The unicycle has 1 wheel. // The unicycle's wheel loading is 12.5 pounds on the single tire. // The unicycle weighs 12.5 pounds.
Objects
Objects are the basic run-time entities in an object-oriented system. They may represent a person, a place, a bank account, a table of data or any item that the program must handle. They may also represent user defined data such as vectors, time and lists. Programming problem is analyzed in terms of objects and the nature of communication between them. Program objects should be chosen such that they match closely with the real-world objects. When a program is executed, the objects interact by sending massage to one another.
For example, if “customer” and “account” are two objects in a program, then the customer object may send a message to the account object requesting for the bank balance, Each object contains data and code to manipulate the data. Object can interact without having to know details of each other’s data or code. It is sufficient to know the ” of massage accepted and the type of response returned by the objects.