Is Android's BaseAdapter an example of Adapter pattern?

前端 未结 1 471
深忆病人
深忆病人 2021-01-17 19:18

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

相关标签:
1条回答
  • 2021-01-17 20:01

    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.

    0 讨论(0)
提交回复
热议问题