음, 완전히 순진 시도 :
public interface Condition<Type T> {
public boolean process(T object);
}
ArrayList row = new ArrayList<Condition>(10);
row.add(new Condition<YourObject>() {
public boolean process(YourObject obj) {
if (obj.property > 0) return true;
else return false;
});
row.add(new Condition<YourObject>() {
public boolean process(YourObject obj) {
if (obj.property2 == 100) return true;
else return false;
});
이 그럼 당신은 반복 것 :
for (Condition<YourObject> cond : row) {
if (! cond.process(yourobj)) break;
}
약간 더 복잡한 예를 들어 당신이 당신의 의사 결정 테이블을 작성할 수 있습니다 자바 스크립트에서 훨씬 더 간결하게, 그리고 아마도 Beanshell을 사용하여 논리를 실행하십시오. 나는 당신에게 예제를 게시하기 전에 이것에 약간의 껍질과 강타를해야 할 것입니다.
예를 게시 한 사용자가 원하는대로 간단한 스칼라 루틴을 만들 수 있습니다. 편집
:
그래서 좀 연구와 생각을했고,으로 Beanshell 위해 그렇게 같은 것을 사용할 수 있습니다
import bsh.Interpreter;
Interpreter i = new Interpreter(); // Construct an interpreter
YourObject yourObject = new YourObject();
i.set("myObject", yourObject);
// Source an external script file
i.source("somefile.bsh");
을 그리고 somefile.bsh은 다음과 같습니다
var rules = new Array();
rules.push(function(var) {
if (var.getProperty() == 0) return true;
else return false;
});
rules.push(function(var) {
if (var.getProperty() < 1000) return true;
else return false;
});
... more rules ...
for (var func in rules) {
if (!func(myObject)) break;
}
이렇게하면 Java 소스를 다시 컴파일하는 것보다 규칙을 변경할 수있는 유연성이 향상됩니다.
당신은 100 원 "행"
와우, 감사합니다. Chris. 나는 이것으로 무언가를 할 수 있다고 생각한다. 나는 그것을 소용돌이 치게 할 것이다. – Elwood