Why adapter classes are important? Compare it with listener interface with suitable example.
The Adapter class provides the default modification of all methods of an interface; we don't need to modify all the methods of the interface so we can say it reduces coding burden. Sometimes or often we need a few methods of an interface. For that the Adapter class is very helpful since it already modifies all the methods of an interface and by implementing the Adapter class, we only need to modify the required methods.
Advantages of the Adapter class
● Assists unrelated classes to work together.
● Provides a way to use classes in multiple ways.
● Increases the transparency of classes.
● Its provides a way to include related patterns in a class.
● It provides a pluggable kit for developing applications.
● It makes a class highly reusable.
Comparison between adapter class and listener interface
In an adapter class, there is no need for implementation of all the methods presented in an interface. It is used when only some methods of defined by its interface have to be overridden.
In a listener, all the methods that have been declared in its interface have to be implemented. This is because these methods are final.
Comments
Post a Comment