Implementing business logic with the Drools rule engine

Source: Internet
Author: User

Introduction: Using the Rules engine can reduce the maintenance and scalability costs of applications by reducing the complexity of components that implement complex business logic. This updated article shows how to use the open source Drools rule engine to make Java™ applications more adaptable to change. The Drools project introduces a new local rule expression language and an Eclipse plug-in that makes Drools easier to use than ever before.

Most of the complexity required to apply to today's software products is behavioral and functional, resulting in complex business logic for component implementations. The most common way to implement business logic in a Java EE or J2SE application is to write code to implement the rules and logic of the requirements document. In most cases, the complexity of the code makes it a daunting task to maintain and update the business logic of the application, even for experienced developers. Any changes, however simple, will still produce the cost of recompiling and redeploying.

The rules engine attempts to resolve (or at least reduce) the problems and difficulties inherent in the development and maintenance of application business logic. The rule engine can be viewed as a framework for implementing complex business logic. Most rule engines allow you to use declarative programming to express results that are valid for some given information or knowledge. You can focus on facts that are known to be true and their results, the business logic of the application.

There are multiple rule engines available, including commercial and open source choices. The business rules engine usually allows you to express rules in a special English-like language. Other rules engines allow you to write rules using scripting languages, such as Groovy or Python. This updated article introduces you to the Drools engine and uses the sample program to help you understand how to use Drools as part of the business logic layer in your Java application.

More things are changing ...

As the saying goes, "the only thing that remains unchanged is change." "This is how the business logic of software applications is." Components that implement application business logic may have to change for the following reasons:

Fix code defects during development or after deployment

To deal with a special situation, that is, the customer at first did not mention the business logic to take into account

Handle customer-changed business objectives

Conforms to the organization's use of agile or iterative development processes

If these possibilities exist, there is an urgent need for an application that can handle business logic changes without too much complexity, especially if the developer who changed the complex if-else logic is not the developer who previously wrote the code.

Drools is an open source rules engine written in the Java language and uses the RETE algorithm to evaluate the rules that are written. Drools allows you to express business logic in a declarative manner. Rules can be written in a non-XML native language for easy learning and understanding. Also, the Java code can be embedded directly into the rules file, which makes Drools's learning more appealing. Drools also has other advantages:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.