Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Android's BaseAdapter an example of Adapter pattern?

Does Android's class BaseAdapter have "Adapter" in its name because it follows the Adapter pattern or is it just a coincidence?

like image 720
fhucho Avatar asked Nov 21 '12 14:11

fhucho


People also ask

What type of pattern is Adapter?

In software engineering, the adapter pattern is a software design pattern (also known as wrapper, an alternative naming shared with the decorator pattern) that allows the interface of an existing class to be used as another interface.

How many types of adapters are there in Android?

Android provides several subclasses of Adapter that are useful for retrieving different kinds of data and building views for an AdapterView ( i.e. ListView or GridView). The common adapters are ArrayAdapter,Base Adapter, CursorAdapter, SimpleCursorAdapter,SpinnerAdapter and WrapperListAdapter.

What are the two versions of Adapter pattern?

If you do some research on the adapter pattern, you will find two different versions of it: The class adapter pattern that implements the adapter using inheritance. The object adapter pattern that uses composition to reference an instance of the wrapped class within the adapter.


1 Answers

From Wikipedia

In computer programming, the adapter pattern (often referred to as the wrapper pattern or simply a wrapper) is a design pattern that translates one interface for a class into a compatible interface.1 An adapter allows classes to work together that normally could not because of incompatible interfaces, by providing its interface to clients while using the original interface.

So, let's discect that. BaseAdapters specify an interface to use for programs that need adapters. In fact, this interface is called Adapter. This interface specifies the information needed to take an arbitrary list, and convert it to an arbitrarily long set of Views. BaseAdapter thus adapts your custom input format (In particularly, if you extend it), to the Adapter interface. Thus, it is an Adapter design pattern.

like image 126
PearsonArtPhoto Avatar answered Sep 17 '22 05:09

PearsonArtPhoto