Benefits of using globals

In Chapter 5, Understanding KIE Sessions, global variables were introduced as a way of interacting with external services. Even if the chapter never explicitly stated this, its tests showed another important benefit of using global: different implementations of the same global may be provided, depending on the context. Right now, the particular context that we are interested in is the testing context.

When testing, mock versions of the global variables requiring interaction with external services, can be provided. These mock variables will immensely reduce the complexity and boiler-plate code required by our tests.

Let's take the following example from the code bundle of Chapter 5, Human Readable Rules:

global AuditService ...

Get Mastering JBoss Drools 6 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.