Rules engine

Preview:

Citation preview

Rules EngineDESIGN PATTERNS

Rules engine Replacing imperative model:

◦commands in sequence with conditionals and loops◦set of rules – each rule has condition and action

Rules engine address the following issueif car.owner.hasCellPhone then premium += 100;if car.model.theftRating > 4 then premium += 200;if car.owner.livesInDodgyArea && car.model.theftRating > 2 then premium += 300;

The solution

Create a bunch objects with conditions and actions

Store them in a collections

Run thought them to evaluate the conditions

Execute the actions

Rules engine diagram

What are the benefits Single Responsibility Principle (SRP)

Open/Close Principle (OCP)

Liskov substitution principle (LSP)

Interface segregation principle

Dependency inversion principle

• Algorithms can be selected on the fly

Strategy pattern

• Combinable business logic in a Boolean fashion

Specification pattern

• Command objects are handled or passed on to other objects by logic-containing processing object

Chain of responsibility

pattern

Recommended