Sunday, June 26, 2016

Four basic principles of OOP

Four major principles of Object-Oriented Programming (OOP)

  1. Data Abstraction
  2. Encapsulation
  3. Inheritance
  4. Polymorphysm


Data Abstraction

  • Any representation of data in which implementation details are hidden. (Showing only what is necessary)
  • Abstraction is a thought process (for e.g. we write design document with high level details such as method name and its return type i.e. we just say CalculateTax() without mentioning the rest of the details)



Encapsulation


  • Ability to provide users a well defined interface to a set of functions which hides internal working (Hide complexity)
  • Encapsulation is implementation side i.e. for e.g. while implementation all things are taken care such as IncomeAmount > 0 etc. which hides complexity while calling/using the method 


Inheritance

:
Inheritance enables you to create new classes that reuse, extend, and modify the behavior that is defined in other classes. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class. A derived class can have only one direct base class. However, inheritance is transitive. If ClassC is derived from ClassB, and ClassB is derived from ClassA, ClassC inherits the members declared in ClassB and ClassA.
 

Polymorphysm
: Polymorphysm is of two types
    Static and dynamic polymorphysm
  • Static
  • Dynamic

No comments:

Post a Comment