|Lesson 3 ||Understanding objects and classes |
|Objective||Explain the Concepts of Objects and Classes|
Understanding Objects and Classes in Java
The whole basis of OOP is the object, which is a combination of data and the procedures that act on the data.
Procedures in an object are referred to as methods, while data is referred to as member data. This merger of data and methods is known as encapsulation,
and provides a means of more accurately modeling real-world objects.
Benefit of Objects
To get a better grasp of the benefit of objects, think for a moment about the common characteristics of real-world objects.
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 ID, name, date of birth, email address,
and so on, 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.
Classes represent Templates