12
Rules Engine DESIGN PATTERNS

Rules engine

Embed Size (px)

Citation preview

Page 1: Rules engine

Rules EngineDESIGN PATTERNS

Page 2: Rules engine
Page 3: Rules engine

Rules engine Replacing imperative model:

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

Page 4: Rules engine

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;

Page 5: Rules engine

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

Page 6: Rules engine

Rules engine diagram

Page 7: Rules engine

What are the benefits Single Responsibility Principle (SRP)

Open/Close Principle (OCP)

Liskov substitution principle (LSP)

Interface segregation principle

Dependency inversion principle

Page 8: Rules engine
Page 9: Rules engine
Page 10: Rules engine

• 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

Page 11: Rules engine