Tuesday, March 17, 2015

OOPs Concepts .

# Object Oriented Programming : OOP is a method of programming.The main purpose of object oriented programming is that it simplify the design, coding by providing re-usability and readability and also debugging of a program is easier.

-Using this it is easy to identify where to add functions and its related data and which function is used to modify data.
-Features of oops :

[1] Object :-Objects is real world entity that is identify by its unique name.Object consist properties(attributes) and behaviours(methods).

For example a car is a object that have properties like colour, brand name etc. and behaviours like it can move forward and backward.

[2] class : Class is template from which object is created that contains variables for storing data and methods to performing operations on these data.Class have collection of similar type objects.

[3] Inheritance : Process of accessing the behaviours of base class by its derived class. Main advantage of inheritance is re-usability of the code.

(i) Single Inheritance : When a single base class is inherited by a single derived class then the inheritance is called as single inheritance.
For example parent child relationship.

(ii) Multilevel Inheritance : A base class inherited by derived and this derived class also inherited by its derived class.
For example grandfather's behaviours inherited by father and father's behaviours inherited by son.

(iii) Hierarchical Inheritance : A base class is inherited by more than one derived class.
For example sparrow, peacock, parrot inherits behaviours of bird class.

(iv) Hybrid Inheritance : Combination of all type of inheritance.

(v) multiple Inheritance : If a derived class inherits properties of more than one base class.
For example duck can swim and also fly.

-Ruby does not support multiple inheritance because it produce a conflict. For example if both the base class have same name then this will produce a confusion.

-So in ruby we can achieve multiple inheritance using module. Module provides a mixin facility. In mixin we can create modules that contains method and we can include more than one modules into our class and we can call modules method using object of class.

[4] Abstraction : Abstraction is the process of hiding implementation and showing only functionality to user.

For example Remote is a interface between user and TV.Using this we can on/off TV but we don't how to circuit works inside remote.
[5] Abstract class : Abstract class is class that has undefined "abstract" methods, which are left for subclasses to define. Abstract method does not have implementation.

For example each bike has a start methods but may be a different technique for different bike for start. Some bike starts by kick and some starts by pressing button.
So we can declare start method as a abstract method and we can implements it in derived class for new bike.

[6] Encapsulation : Encapsulation is a process of binding data and methods together.Encapsulation protect data from unwanted access or alteration by making it private.
Encapsulation = Abstraction + Data Hiding.

[7] Polymorphism : Different behaviours at different instances depend upon the data passed in the operation. Polymorphism increase code readability.

For example a software engineer performs many task such as sometimes he performs coding, sometimes he performs testing, sometimes he performs analysis. So software engineer is one but he is performing different task depending upon requirement.

There are two types of polymorphism.

(i) Compile time polymorphism : It is achieved by method overloading. In this, call to a overloaded method is decide at compile time.

(ii)Runtime Polymorphism : It is achieved by method overriding. In this, call to a method is decide at runtime.

12 comments:

  1. Awesome blog. I never understood oops this way till i read this blog. Great work. Thanks :)

    ReplyDelete
  2. I am not able to find a difference in Hierarchical Inheritance & Multilevel Inheritance example.

    In Hierarchical Inheritance "For example sparrow, peacock, parrot inherits behaviours of bird class", so do they in Multilevel Inheritance. Please if you can explain.

    ReplyDelete
  3. @anil_singh, hi i'm from pakistan, you did a great job,these concepts in any oop book seems like useless but here you just clear all confusions.
    thanks and your blog is awesome

    ReplyDelete
  4. Amazing blog about the various informative information on the programming languages. Android Training in Bangalore

    ReplyDelete
  5. It was really a nice article and i was really impressed by reading this Ruby on Rails Online Training Bangalore

    ReplyDelete
  6. Nice post ! Thanks for sharing valuable information with us. Keep sharing..Ruby on Rails Online Course Hyderabad

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Expected to form you a next to no word to thank you once more with respect to the decent recommendations you've contributed hereindustrial course in chennai

    ReplyDelete
  9. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
    Data Science Training in Chennai
    Robotic Process Automation Training in Chennai
    Cloud Computing Training in Chennai
    Data Warehousing Training in Chennai
    Dev Ops Training in Chennai

    ReplyDelete
  10. This is very great thinks. It was very comprehensive post and powerful concept. Thanks for your sharing with us. Keep it up..
    Oracle Training in Chennai | Oracle Training Institutes in Chennai

    ReplyDelete