1700484259
public interface ISpecification{
1700484260
1700484261
//候选者是否满足要求
1700484262
1700484263
public boolean isSatisfiedBy(Object candidate);
1700484264
1700484265
//and操作
1700484266
1700484267
public ISpecification and(ISpecification spec);
1700484268
1700484269
//or操作
1700484270
1700484271
public ISpecification or(ISpecification spec);
1700484272
1700484273
//not操作
1700484274
1700484275
public ISpecification not();
1700484276
1700484277
}
1700484278
1700484279
组合规格书实现与或非的算法,如代码清单37-23所示。
1700484280
1700484281
代码清单37-23 组合规格书
1700484282
1700484283
public abstract class CompositeSpecification implements ISpecification{
1700484284
1700484285
//是否满足条件由实现类实现
1700484286
1700484287
public abstract boolean isSatisfiedBy(Object candidate);
1700484288
1700484289
//and操作
1700484290
1700484291
public ISpecification and(ISpecification spec){
1700484292
1700484293
return new AndSpecification(this,spec);
1700484294
1700484295
}
1700484296
1700484297
//not操作
1700484298
1700484299
public ISpecification not(){
1700484300
1700484301
return new NotSpecification(this);
1700484302
1700484303
}
1700484304
1700484305
//or操作
1700484306
1700484307
public ISpecification or(ISpecification spec){
1700484308
[
上一页 ]
[ :1.700484259e+09 ]
[
下一页 ]