Drools - DSL
Jump to navigation
Jump to search
What is Domain Specific Language ⌘
- " a way of creating a rule language that is dedicated to your problem domain"
- DSL is ultimately transformed to rules (mvel or java)
- .dsl file contain the transformations (mapping)
- DSLs have no impact on the rule engine at runtime, they are just a compile time feature
什么是领域特定语言 。
- " 创建规则的语言,为你的问题领域而特别设计"
- DSL最终将转换为规则 (mvel or java)
- .dsl文件包含了转换器 (mapping)
- DSLs 在运行时刻(runtime)对规则引擎无影响,他们只用于编译
When to use DSL ⌘
- Your requirements should be executable and always in sync with what is actually executed
- Analysts can focus on "logic proper"
- You already have a rules written in SBVR or other standard (which is consistent and detailed enough to be easily translated into executable rules)
- You need "templates" for conditional elements and consequence actions that are used repeatedly in your rules (with minor variations)
什么时候使用 DSL 。
- 你的需求应该能被执行并且和实际执行的要永远同步
- 分析师可以专注于“逻辑准确”( "logic proper")
- 你已经有SBVR或者其它标准 (一致且足够详细,可以很容易翻译为可执行规则)写的规则
- 你的规则里多处需要条件判断和结果动作(consequence actions),你需要一套模板(需要稍有改动)
DSL in Guvnor ⌘
Create New -> New DSL
[when]Order is greater than {totalOrder} = sc :ShoppingCart( $totalPrice : totalPrice > {totalOrder}) [then]Set discount to {discount} = sc.setTotalPrice( $totalPrice * (1-{discount}) ); update(sc);
- Create New -> New Rule
- Type (format) of rule: DSL or Guided Ruls
dilect "mvel" when Order is greater than 10000 then Set discount to 0.1
Use the test created for tall order discount
Guvnor里的DSL 。
Create New -> New DSL
[when]Order is greater than {totalOrder} = sc :ShoppingCart( $totalPrice : totalPrice > {totalOrder}) [then]Set discount to {discount} = sc.setTotalPrice( $totalPrice * (1-{discount}) ); update(sc);
- Create New -> New Rule
- Type (format) of rule: DSL or Guided Ruls
dilect "mvel" when Order is greater than 10000 then Set discount to 0.1
Use the test created for tall order discount
Eclipse ⌘
See 08.1DSL folder
Eclipse 。
见 08.1DSL 文件夹