Wednesday, 22 August 2012

Object oriented programming principles

There are three basic OOPS principle which includes :
  1. Inheritance
  2. Encapsulation
  3. Polymorphism
Each of these principles can be explained as:


  1. Inheritance:  It is the process by which one object inherits the properties of another object. This is important as it supports the concept of hierarchical classification. Without the use of hierarchies, each object would need to define all of its characteristics explicitly. However, by use of inheritance, an object need only define those qualities that make it unique within its class. It can inherit its general attributes from its parent. Thus, it is the inheritance mechanism that makes it possible for one object to be a specific instance of a general case. Inheritance interacts with encapsulation as well. If a given class encapsulates some attributes then any subclass will have same attributes plus any that adds as part of its specialization..
  2. Encapsulation:  It is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. It is a protective wrapper that prevents the code and data from being arbitrarily accessed by other code defined outside the wrapper. Access to the code and data inside the wrapper is tightly controlled through a well-defined interface. In java, the basis of encapsulation is the class. When we create a class, we will specify the code and data that constitute that class.
  3. Polymorphism:  It is a feature that allows one interface to be used for a general class of actions. The specific action is determined by the exact nature of the situation. It is possible to design a generic interface to a group of related activities. This helps to reduce complexity by allowing the same interface to be used to specify a general class of action. It is the compiler's job to select the specific action as it applies to each situation.

No comments:

Post a Comment