Tag: 规范模式

设计模式在java中使用数百个if else实现业务规则

我必须使用数百行以下代码实现某些业务规则 if this then this else if then this . . // hundreds of lines of rules else that 我们是否有任何设计模式可以有效地实现这一点或重用代码,以便它可以应用于所有不同的规则。 我听说过规范模式,它创建了类似下面的内容 public interface Specification { boolean isSatisfiedBy(Object o); Specification and(Specification specification); Specification or(Specification specification); Specification not(Specification specification); } public abstract class AbstractSpecification implements Specification { public abstract boolean isSatisfiedBy(Object o); public Specification and(final Specification specification) […]