This chapter covers
- Evolving the example DSL to write business rules with
- Implementing business rules
- Generating code for running business rules
Our example DSL allows us to define a (single) record type in a type-safe way, and to generate a Runtime UI from that. That’s useful but not very valuable yet. It’s especially weird that the user of the UI is able to set the discount themselves. The discount should be computed by the Runtime based on logic defined by the business.
In chapter 1, I promised that we’d be building a DSL with which domain experts could write down business logic. The following Figure shows an example of some business logic defined as a business rule:
(This Figure is a screenshot of a part of the Domain IDE that we’ll have built by the end of this chapter.) This business rule expresses that when the rental period contains a Saturday, then 10% is to be added to the discount. For a lot of domains, a major part of business logic can be very well expressed as business rules. Being able to specify business rules with a DSL brings a lot of power, regardless of the domain.