Android and Design Patterns Talking About Strategy Patterns

In the process of software development, in order to realize a certain function, there can be multiple algorithms or strategies, and various algorithms can be encapsulated and replaced with each other. This mode is the strategy mode.

  • Various algorithms are abstracted into a unified interface, and dynamic replacement is achieved by inputting different algorithms according to business requirements.
  • The application example of the strategy mode in android, the interpolator mode in the value animation, has three kinds of uniform interpolators, acceleration and deceleration interpolators, and deceleration interpolators. These three interpolators can be replaced with each other according to different situations.
  • Another application of the strategy pattern in android is the adapter for ListView. The adapters of ListView include ArrayListAdapter, SimpleAdapter, and BaseAdapter; these three adapters can be selected according to different needs, and can be replaced by each other in some cases. Obviously using the strategy pattern.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324791943&siteId=291194637