Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an adapter class?

Tags:

I googled and investigated, but I still need some clarification: Are an adapter class and a controller class similar? If not, in what way they do differ?

Kindly explain.

like image 263
Naruto Avatar asked Apr 16 '12 08:04

Naruto


People also ask

What is an adapter class C++?

Adapter in C++ An "adapter" class is defined that publicly inherits the interface of the abstract class, and privately inherits the implementation of the legacy component. This adapter class "maps" or "impedance matches" the new interface to the old implementation.

What are adapters in Java?

Adapter is a structural design pattern, which allows incompatible objects to collaborate. The Adapter acts as a wrapper between two objects. It catches calls for one object and transforms them to format and interface recognizable by the second object.

What is the responsibility of adapter class?

The adapter class implements the expected interface and keeps a reference to an object of the class you want to reuse. The methods defined by the interface call one or more methods on the referenced object and return a value of the expected type.


1 Answers

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.

like image 82
AlexR Avatar answered Sep 18 '22 22:09

AlexR