Monday 9 January 2017

OOP Principles in Java


                                             


The 3 Principles of OOP ( Object Oriented Programming ) 

- All Object Oriented Programming languages provide mechanisms
   that help you implement the object - oriented model.

- These are 
  1. Encapsulation
  2. Inheritance
  3. Polymorphism


Encapsulation 

- Encapsulation is a mechanism that binds together code and the 
  the data it manipulates and keeps both safe from outside 
  interference and misuse.

- Encapsulation can also be considered as a 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.

- The power of encapsulated code is that everyone knows how to       access it and thus can use it regardless of the implementation           details without any fear of side effects.

- In java , the basis of encapsulation is class. The Class defines the     structure and behaviour that will be shared by a set of objects.
  Each object of a given class contains the structure and behavior       defined  by the class , so they are also referred to as Instances Of   Class. 

- When we create a class , we specify the code and data that               constitute that class which are called as members of class .The       data defined by the class are referred to as member variables or     instance variables. The code that operates on that data is referred   to as member methods or just methods

- Since the purpose of class is to encapsulate the complexity , there   are mechanism for hiding the complexity of the implementation       inside the class. Each method or variable in a class may be marked   Private or Public

- The public interface of a class represents everything that external
   users of class need to know or may know. The private methods 
   and data can only be accessed by the code that is a member of 
   the class i.e the any other code that is not the member of the
   class cannot access private method or variable.

Inheritance 

- Inheritance is the process by which one object acquires the             properties of another object. It 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 but with the use of inheritance,
   an object need to define only those qualities that makes a unique 
   within class.

- Inheritance interacts with the encapsulation as well. If a given         class encapsulates some attributes , then any subclass will have 
  the same attributes plus any that it adds as part of its 
  specialization. This key concept which lets object oriented 
  programs grow in complexity linearly rather than geometrically.


Polymorphism



- Polymorphism is derived from the Greek word which means 
  " Ability to take many forms" . polymorphism 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. The concept of polymorphism is also referred to as
   " One Interface , Multiple Methods." This means that it is 
   possible to design a generic interface to a group of rekated
   activities. 

- This help reduce the complexity by allowing the same interface 
   to be used to specify a general class of action. It is compiler's job 
   to select the specific action as it applies to each situation. The
   programmer need not to make selection manually.

                                                                   By: Knowledge Bits

No comments:

Post a Comment

Video of the Day

Contact us

Name

Email *

Message *