Strategy Pattern Design

Purpose:

To separate strategies and to enable fast switching between them. Also this pattern is a good alternative to inheritance (instead of having an abstract class that is extended).

Examples:

  • Sorting a list of objects, one strategy by date, the other is by id.
  • Simplify unit testing: e.g. switching between file and in-memory storage.

UML:

 

posted @ 2019-06-10 05:37  Victor!!!!  阅读(84)  评论(0编辑  收藏  举报