Software programmers are used to a procedural approach when it comes implementing Business requirements. The consequence is that the business rule implementation solely depends on the competence and understanding the software developer has of the Business Rules he has to implement. This limitation was already seen and identified by researches. Object oriented programming may be seen as “the solution” to business implementation and agility and many developers rely on this paradigm. In the end, Object oriented approach ends up with the classical “Spaghetti code“. To avoid this ending, a new approach was taken called “declarative programming“. This is a big shift and we shall try to focus on that before learning the tooling around drools.
- Drools start from the base concepts (there are few and is concentrated on the core engine) up to more language concepts
- BRMS(Business Rule Management System) will introduce the management tooling (called workbench/Business Central) around the lifecycle of the rule artifact. but the workbench also introduces more artifacts type like decision table, rule templates, etc.. that will help when modeling business requirements.
- BRMS runtime starts to introduce possible software architectures in a real project. In our exercise, we will use the ideas that we describe in that part.
When working with drools, there are things you have to define :
- The data model on which the rules apply. As we are working in the java language, a data model is a set of java classes.
- Rules which are going on one side (called left side or LHS) express constraints on the data model, which here class name and their attributes and on the other side (called right side or RHS) which will act on the facts which are in the working memory.
- When you want to apply some rules on some data, you will instantiate a java class and give it to the rule engine. This instance is called a Fact object.
- To work with the rule engine, we have to instantiate a KieContainer. We will see later how to program it. This kieContainer contains a set of rules. The KieContainer can also be used in jbpm and Optaplanner projects.
- When you want to work with drools, you have to get a KieSession from the KieContainer. This KieSession will allow you to give facts to the rule engine and to ask to fire rules.