I googled and investigated, but I still need some clarification: Are an adapter class and a controller class similar? If not, in what way do they differ?
Kindly explain.
Adapter is a pattern that provides default (often empty) implementation of interface or abstract class. For example MouseAdapter
provides empty implementation of MouseListener
interface. It is useful because very often you do not really use all methods declared by interface, so implementing the interface directly is very verbose.
Controller is a part of MVC - Model-View-Controller pattern. No direct relation with Adapter.
Adapter Classes
and couldn't find any,, where can i find it?
The job of an adapter is primarily to make some object work in a situation where a different interface is expected.
A controller (in an MVC sense) is similar in that it's an intermediary between model and view classes, but different in that it generally embodies a lot more knowledge about how the program is supposed to work. A controller does more than just adapting one interface to another.
Say you've got a Color class that has a setColor(red, green, blue)
method. You also have some code that expects a setColor(hue, saturation, value)
method. You can create an adapter class that wraps your Color class and implements the expected method in terms of the one your Color class provides.
ex--- instead of implementing Servlet(I) if we extends GenericServlet(AC) then we provide implementation for Service()method we are not require to provide implementation for remaining meyhod..
Generic class Acts as ADAPTER class for Servlet(I).
An adapter class provides the default implementation of all methods in an event listener interface. Adapter classes are very useful when you want to process only few of the events that are handled by a particular event listener interface. You can define a new class by extending one of the adapter classes and implement only those events relevant to you.
an adapter class provide default implementations of all methods in an event listener class,methods are define in that class with empty body; we can override only required methods of that class ,by inherit that class. Adapter class decrease no of lines of coding.
every listener interfaces have 1 or more methods. interfaces which contain more than 1 method have adapter classes ...each adapter class contains all the methods of that interface. if we are writing a method of an interface in a class then you should write all the methods ...some of the interfaces of listener contains more than 6 methods ....so inorder to have less burden on programmer they invented these adapter classes.so we extend these adapterclass to our class and we write our method hence it overrides the adaptermethod....so we lose the risk of writing all the methods
Adapter objects in android provide view elements for (example) lists - thus they clearly belong to view part of MVC paradigm
Advantages of an Adapter Class:
A class which adapts methods of another class by giving different names to essentially the same methods (i.e. push(Stack) instead of add(ArrayList)) is called an adapter class