Saturday, March 1, 2014

Principles of OOPS

Principles of Object Oriented Programming:

  • Data Encapsulation
  • Data Abstraction
  • Polymorphism
  • Inheritance

Data Encapsulation 

This is the default nature of a class. A  class  encapsulates  (combines)  some  data  values  (fields  or properties)  and some operations (methods) related to the data as a pack. This nature can be called as Data Encapsulation.

Data Abstraction:

The nature of "instance" creation is called as "Data Abstraction". This feature is taken from "structures" in C  languages. (In ‗C‘ language you can create  any  no.  of  structure  variables  based  on  one  structure.  The  structure variables act as instances for the structure). In the same way, you can create any no. of instances (objects) for a class.


The decision making capacity of the compiler is called "Polymorphism".
It is of two types:
  • Compile-time Polymorphism:
          The decision can be made at the time of compilation. This can be implemented with two concepts:
           i)  Method  Overloading:  You  can  write  multiple methods with same name within the same class.
           ii)  Operator  Overloading:  You  can  write  multiple definitions for the same operator.
  • Run-time Polymorphism:
         The decision can be made at run time. This can be implemented with two concepts:
          i)  Templates / Generics:  You  can  pass  any  type  of value as an argument to a method.
          ii)  Interfaces:  Contains  method  declarations  only, doesn‘t contain method definitions.


The  process  of  creating  a  new  class  that  derives  all  the  features  of  another existing class is called as "Inheritance". In other words, we can extend the features of a class.

No comments:

Post a Comment