java Adapter class example

Hi in this post of core java tutorialĀ i will discuss about Adapter class in java. Why adpter class is used. Adpter is design pattern in java. Adpter is somthing that connect two component.

adpter class example in java

adpter class example in java

Adapter is a pattern that provides default (often empty) implementation of interface or abstract class. . It is useful because very often you do not really use all methods declared by interface, so implementing the interface directly is not usefull.

Let see with example

In the example Pin is interface that contacin five methods.

Adpter class give default implementation to Pin interface methods.

Changer class extend Adpter class and override one of its method. So instead of implementing five method out of which four are of no use in Changer class it just uses one method which it override from Adpter class.

This is all in this tutorial of core java. I will get back soon with next interesting tutorial.

About the Author: devender kumar

java/j2EE developer

Comments are closed.