To get a better grasp of the benefit of objects, think for a moment about the common characteristics of real-world objects.
1) Snakes, rockets, light bulbs, and even people all share two common characteristics: 1) state and 2) behavior.
2) An object's state determines the condition the object is in, which is defined by its attributes.
3) An object's behavior consists of the collection of actions that the object can take.
4) Software objects are similar to real-world objects in that they posses two common characteristics: 1) state and 2) behavior.
5) Data and methods determine the state and behavior of an object, respectively.
6) The logical similarities between real-world objecs and software objects make it easier for programmers to solve real-world problems.
In object-oriented (OO) programming, an application consists of a series of objects that ask services from each other. Each object is an instance of a class that contains a blueprint description of all the object's characteristics. Contrary to procedural programming, an object bundles both its data (which determines its state) and its procedures (which determines its behavior) in a coherent way. An example of this could be a student object having data elements such as
- date of birth, and
- email address.
and procedures such as registerForCourse, isPassed, and so on. A key difference between OO and procedural programming is that OO uses local data stored in objects, whereas procedural programming
uses global shared data that the various procedures can access directly. This has substantial implications from a maintenance viewpoint. Imagine that you want to change a particular data element (rename it or remove it).
In a procedural programming
environment, you would have to look up all procedures that make use of the data element and adapt them accordingly. For huge programs, this can be a very tedious maintenance exercise.
When you are using an OO programming paradigm, you only need to change the data element in the object's definition and the other objects can keep on interacting with it like they did before, minimizing the maintenance.
OO programming is the most popular programming paradigm currently in use. Some examples of object-oriented programming languages
are Eiffel, Smalltalk, C++, and Java.