Saturday 22 November 2014

Main Components of Object Oriented Technology

When we learn the Object Oriented Programming using Java, we have the knowledge of main components:

  • Objects and Classes
  • Data Abstraction and Encapsulation
  • Inheritance
  • Polymorphism
These are the components of Object Oriented Technology. Let's understand a detailed description of the above component.

Objects

Let's start with an Object. The first thing that we should do in the Object Oriented approach is to start thinking in terms of Objects because in Object Oriented programming object is center point or we can say that the heart of OOP.

Definition: An object is a software bundle of variables and related methods.

Look around right now and you will find many real - world objects such as, your laptop, any dog, your television, your scooter bike, your mobile etc.
Real - world objects share two characteristics: they all have State and Behavior. so, we can think like,
My Dog (My Object) Dog have state (name, color, hungry) and behavior (barking, fetching, wagging tail).

Software Objects are conceptually similar to real world objects. they also consist of state and behavior. An object stores its state in fields (variables in some programming languages) and exposes its behavior through methods (function in some programming language).

Class

In the real world, you often have many objects of the same kind. For example, your dog is just one of many dogs in the world.  In object-oriented terminology, we say that your dog object is an instance of the class known as animal. Dogs have some state and behavior in common.

In object-oriented software, it is also possible to have many objects of the same kind that share characteristics.

Definition: A class is a blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind.


Data abstraction and encapsulation

The wrapping up of data and functions into a single unit is known as encapsulation. This is one of the strong features of the object oriented approach. The data is not directly accessible to the outside world and only the functions, which are wrapped in the class, can access it. Functions are accessible to the outside world. These functions provide the interface to access data. If one wants to modify the data of an object, s/he should know exactly what functions are available to interact with it. This insulation of the data from direct access by the program is known as data hiding.

Abstraction refers to the act of representing essential features without including the background details to distinguish objects/ functions from other objects/functions. In case of structured programming, functional abstraction was provided by telling, which task is performed by function and hiding how that task is performed. A step further, in the Object Oriented approach, classes use the concept of data abstraction. With data abstraction, data structures can be used without having to be concerned about the exact details of implementation. As in case of built-in data types like integer, floating point, etc. The programmer only knows about the various operations which can be performed on these data types, but how these operations are carried out by the hardware or software is hidden from the programmer. Similarly in Object Oriented approach, classes act as abstract data types. Classes are defined as a set of attributes and functions to operate on these attributes. They encapsulate all the essential properties of the objects that are to be created.

Inheritance

Inheritance is the process by which objects of one class acquire the properties of objects of another class in the hierarchy. For example, the scooter is a type of the class two-wheelers, which is again a type of (or kind of) the class motor vehicles.

Definitions: A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). The class from which the subclass is derived is called a superclass (also a base class or parent class).
Types of Inheritance

Polymorphism

Polymorphism means the ability to take more than one form of the same property. The dictionary definition of polymorphism refers to a principle in biology in which an organism or species can have many different forms or stages. This principle can also be applied to object - oriented programming and languages like the Java language. Subclasses of a class can define their own unique behaviors and yet share some of the same functionality of the parent class.


Polymorphism