Object Programming  «Prev  Next»
Lesson 3 Understanding objects and classes
ObjectiveExplain 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 methods 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.

  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.

Understanding Objects

Object-oriented Programming

In object-oriented (OO) programming, an application consists of a series of objects that request 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
  1. ID,
  2. name,
  3. date of birth, and
  4. email address.
and procedures such as registerForCourse, isPassed, and so on.

Key Difference between OO and Procedural Programming

A key difference between OO and procedural programming is that
  1. OO uses local data stored in objects,
  2. whereas procedural programming uses global shared data that the 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

A class is a template, or specification, that defines a type of object.
Class Template Specification
Understanding Objects and Classes

Ad Java Reference