Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
一个类A有3个boolean字段,这个类有一组对象。我需要对每个对象执行不同的处理,就其 3 个字段的组合而言。我应该采用什么模式?
A
boolean
public class A { boolean a, b, c; }
谢谢你。
丹尼尔
查找registry图案。本质上,您定义一个接口AHandler并为您要处理的每个组合实现它。
registry
AHandler
然后,创建一个Map<A, AHandler>并使用处理程序对其进行静态初始化。查找此地图以找到处理每个组合的处理程序。
Map<A, AHandler>