Is Android's BaseAdapter an example of Adapter pattern?

倖福魔咒の 提交于 2019-12-01 14:26:43

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/13495405/is-androids-baseadapter-an-example-of-adapter-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!