Académique Documents
Professionnel Documents
Culture Documents
Introduccion
Reglas de negocio
2
Problemas con la solucion
tradicional
Los requerimientos de la capa de negocios, son
los que cambian mas a menudo.
Los cambios generalmente involucran tiempo y
retrabajo.
Una solucion standard utilzando algun lenguaje
imperativo (Java, C#) , terminara rapidamente en
spaghetti code y en montones de sentencias if-else
anidadas.
3
Problemas con la solucion
tradicional
Por ejemplo;
if (customer.getLevel() == Level.Gold) {
● //do something for Gold customer
} else if (customer.getLevel() == Level.Silver) {
● if (customer.getAccounts() == null) {
● //do something else for Silver customer with no accounts
● } else {
● for (Account account : customer.getAccounts()) {
● if (account.getBalance < 0) {
● }
● }
● }
}
4
La solucion
5
Introduciendo Drools
6
Introduciendo Drools
7
Ventajas
Facil de entender
Mantenimiento mas facil
Reduce complejidad
Flexibilidad
8
Drools Expert
Rule engine
Ejemplo reglas con drools
Problema:
Calcular la factura de un servicio
telefonico
10
Escribiendo regla
rule "morningPhoneCall"
when
$p : PhoneCall(charged == false, startDateTime.hourOfDay < 12)
then
modify ($p) {
setBasePricePerSecond(new BigDecimal("0.05"));
}
end
rule "afternoonPhoneCall"
when
$p : PhoneCall(charged == false, startDateTime.hourOfDay >= 12)
then
modify ($p) {
setBasePricePerSecond(new BigDecimal("0.20"));
}
end
11
Drools Eclipse
Eclipse-based Tooling
Features
Wizards
Drools runtimes (classpath)
Textual Rule Editor
● Syntax highlighting, code completion, error detection,
outline view, etc.
Guided Editor
Debugging
● Rule breakpoints
● Debug views
13
Textual Rule Editor
14
Domain-specific Rule Editor
15
Drools Guvnor
Knowledge Repository
Guvnor
Technology
● JCR (JSR-170) backend
● Seam + GWT frontend
● WebDav
● Eclipse synchronisation plugin
● Role based security
Authoring
● Decision Tables
● Guided Editor
QA
● Scenario Testing + Rule Verification
17
Business asset storage
18
Guided Editor
19
Decision Tables
20
Scenario Testing
21