Java Source World A Java quick reference blog
Java OOPs concepts:
Abstraction:
Showing the essential and hiding the non-Essential is known as Abstraction.
How to achieve abstraction in java is using Abstract classes and interfaces.
Encapsulation:
Encapsulation is the term given to the process of hiding the implementation details of the object. Once an object is encapsulated, its implementation details are not immediately accessible any more. Instead they are packaged and are only indirectly accessed via the interface of the object.
Many design patterns in java uses encapsulation concept, one of them is Factory pattern which is used to create objects.
Inheritance:
Advantages: Re-usability of code, accessibility of variables and methods of the Base class by the Derived class.
Polymorphism:
The ability to take more than one form, it supports Method Overloading & Method Overriding.
Method overloading:
When a method in a class having the same method name with different arguments (diff Parameters or Signatures) is said to be Method Overloading. This is Compile time Polymorphism.
Using one identifier to refer to multiple items in the same scope.
Method Overriding:
When a method in a Class having same method name with same arguments is said to be Method overriding. This is Run time Polymorphism. Providing a different implementation of a method in a subclass of the class that originally defined the method.
2. Overloading does not block the Inheritance from the Super class , Where as in Overriding blocks Inheritance from the Super Class.
3. In Overloading separate methods share the same name, where as in Overriding Sub class method replaces the Super Class.
4. Overloading must have different method Signatures , Where as Overriding methods must have same Signatures.
Dynamic dispatch:
is a mechanism by which a call to Overridden function is resolved at run time rather than at Compile time , and this is how Java implements Run time Polymorphism.
Dynamic Binding:
Means the code associated with the given procedure call is not known until the time of call the call at run time. (it is associated with Inheritance & Polymorphism).
Continue Reading:
Front Controller Design Pattern
Factory pattern or Factory method pattern
No comments:
Post a Comment