SlideShare a Scribd company logo
Them’s the Rules
by
Micah Breedlove
Using a Rules Engine to Wrangle
Complexity
PHP Dev since ‘98
Symfony Evangelist
@druid628
http://micah.breedlove.in/
Sr. Developer / Team Lead @ iostudio
Who is this guy?
Rules Engines
Drools
Open Rules
Jess
Ruler (PHP)
Ruler
Written by Justin Hileman(BobTheCow)
GitHub: https://github.com/bobthecow/Ruler
Packagist: ruler/ruler
Some definitions
Conditional Logic
“hypothetical logic (of a proposition) consisting
of two component propositions... so that the
proposition is false only when the antecedent is
true and the consequent false.”
How we handle the unknown.
Rules Engines
“A business rules engine is a software system
that executes one or more business rules in a
runtime production environment.”
“An added layer of complexity to carry out,
often complicated, business logic of the
application”
in other words...
Business Logic?
Company policies
Legal Regulations
Examples
Discounts on products purchased
Combination of products
Subscribed services
Additional Fees
Geographical assessment
Risk assessment
What is wrong with this?
if ( $obj->getName() == ‘abc’) { } elseif ($obj->getName() == ‘def’) {
} elseif ($obj->getName() == ‘ghi’) { } elseif ($obj->getName() == ‘jkl’ ) {
} elseif ($obj->getName() == ‘mno’ ) {
} elseif ($obj->getName() == ‘pqr’ && $obj->getClient()->getCategory() !==
‘hotChkn’) {
}elseif ($obj->getName() == ‘Hg(CNO)2’ && $obj->getClientKey() == ‘tuco’){
}elseif ($obj->getName() == ‘blueSky’ && $obj->getClientKey() ==
‘losPollosHermanos’) {
} elseif ($obj->getName() == ‘blueSky’ && $obj->getClientKey() ==
‘heisenberg’){}
...
Should be kept trimmed,
maintained and under control
Or else...
Pandemonium Ensues
Conditional statements are like Kudzu
Fixable?
Something to …
Abstractly handle multiple conditions
With
Minimal conditional logic
and is
Reusable
Simplifies a block into a generic block
Support more than a simple/singular condition
Abstraction
Minimize Conditional Logic
Drop the ever-building conditionals
Replace with smaller defined block
Reusability
Ability to support all existing conditions
Individual rules can be evaluated in other
RuleSets
The saga begins…
if ($bond->getClient()== ‘client1’ && $event->getName() == ‘bond.create’) {
$this->calculateClient1BondAdjustments($bond);
} elseif ($bond->getClient() == ‘client1’ && $event->getName() == ‘payment.made’) {
$this->calculateClient1Payment($bond, $payment);
} elseif ($bond->getClient() == ‘client2’ && $event->getName() == ‘bond.create’) {
$this->calculateClient2BondAdjustments($bond);
} elseif ($bond->getClient() == ‘client3’ && $event->getName() == ‘bond.create’) {
$this->calculateClient3BondAdjustments($bond);
} ...
What We Need
If a Bond is made in Collegedale
A $25 fee should be assessed
$rule = $ruleFactory->getBondRules();
$clientRule = [
‘district’ => ‘collegedale’,
‘district_fee’ => ‘25’,
‘fee_adjustment’ => ‘+’
];
$context = new Context([
‘bond_district’ => $bond->getDistrict(),
‘district’ => $clientRule[‘district’],
‘district_fee’ => $clientRule[‘district_fee’],
‘fee_adjustment’ => $clientRule[‘’fee_adjustment’]
]);
$rule->execute($context);
Rule Elements
Ruler - Elements of the Equation
3 Parts
Context
Rule
Execution/Evaluation
Context - All Applicable Data
Variable Data:
‘bond_district’ => ‘collegedale’,
Control Data:
‘district’ => ‘collegedale’,
‘district_fee’ => ‘25’,
‘fee_adjustment’ => ‘+’
Variable Data
Request
User Specific
(includes session)
Control Data
Specific to the Rule
Rule
$rule = $rb->create(
$rb['bond_district']->EqualTo($rb['district'])
);
How the Context Stacks Up
How to evaluate the data
What to evaluate
Variable Data:
‘bond_district’ => ‘collegedale’,
Control Data:
‘district’ => ‘collegedale’,
‘district_fee’ => ‘25’,
‘fee_adjustment’ => ‘+’
Rule (cont.)
Compound Rules
$rule = $rb->create(
$rb->LogicalAnd(
$rb['bond_district']->EqualTo($rb['district']),
$rb['bond_amount']->GreaterThan('20000')
)
);
Evaluation/Execution
Evaluate - (boolean) Did it meet the condition?
Execution - (void) If it’s true do something
Evaluation Example
Rule:
$rule = $rb->create(
$rb['bond_district']->EqualTo($rb['district'])
);
$status = $rule->evaluate($context);
echo $status; // true
Control Data:
‘district’ =>
‘collegedale’,
‘district_fee’ => ‘25’,
‘fee_adjustment’ => ‘+’
Variable Data:
‘bond_district’ => ‘collegedale’
Execution Example
$rule->execute($context);
// output: An additional mileage fee will be charged.
Control Data:
‘district’ =>
‘collegedale’,
‘district_fee’ => ‘25’,
‘fee_adjustment’ => ‘+’
Variable Data:
‘bond_district’ => ‘collegedale’
Rule:
$rule = $rb->create(
$rb['bond_district']->EqualTo($rb['district']),
function() {
echo 'An additional mileage fee will be charged.';
}
);
if ($bond->getClient()== ‘client1’ && $event->getName() == ‘bond.create’) {
$this->calculateClient1BondAdjustments($bond);
} elseif ($bond->getClient() == ‘client1’ && $event->getName() == ‘payment.made’) {
$this->calculateClient1Payment($bond, $payment);
} elseif ($bond->getClient() == ‘client2’ && $event->getName() == ‘bond.create’) {
$this->calculateClient2BondAdjustments($bond);
} elseif ($bond->getClient() == ‘client3’ && $event->getName() == ‘bond.create’) {
$this->calculateClient3BondAdjustments($bond);
} ...
Finally this…
...becomes this
$ruleObject = $rulesRepo->get($event->getName()); // assume bond.create
$context = $ruleObject->getContext();
$context[‘bond’] = $bond;
$rule = $ruleObject->getRule();
$rule->execute($context); // one rule to rule them all
Questions?
Demo Time
Thanks!
Slides: http://sthen.es/mqh4ub20
citations
Jesse (Breaking Bad) - http://replygif.net/i/1323.gif
Kudzu - http://2.bp.blogspot.com/_RTswKzWDHeM/SE198zJTgzI/AAAAAAAAA80/ZKj4haQbiSE/s320/kudzu+house.jpg
MC Hammer - http://24.media.tumblr.com/26d1484f43ff55401f8ead9d03432bb9/tumblr_moctg0LbmC1sn8pc2o1_400.gif

More Related Content

Viewers also liked

SQL Server 2014 Mejoras del DB Engine
SQL Server 2014 Mejoras del DB EngineSQL Server 2014 Mejoras del DB Engine
SQL Server 2014 Mejoras del DB Engine
Eduardo Castro
 
Search Engine Optimization
Search Engine OptimizationSearch Engine Optimization
Search Engine Optimization
SRP Communication & Brand Design
 
Del SEO a las Redes Sociales
Del SEO a las Redes SocialesDel SEO a las Redes Sociales
Del SEO a las Redes Sociales
Abraham Villar
 
Ferran calpe b4_lag
Ferran calpe b4_lagFerran calpe b4_lag
Ferran calpe b4_lag
Ferran5
 
Presentacion Blender
Presentacion BlenderPresentacion Blender
Presentacion Blender
Alfonso de la Guarda Reyes
 
KRITAL AUDIO ENGINE
KRITAL AUDIO  ENGINE KRITAL AUDIO  ENGINE
KRITAL AUDIO ENGINE
Maria Chica Solorzano
 
MARKETING 2.0 Y REDES SOCIALES EN LA EMPRESA
MARKETING 2.0  Y REDES SOCIALES EN LA EMPRESAMARKETING 2.0  Y REDES SOCIALES EN LA EMPRESA
MARKETING 2.0 Y REDES SOCIALES EN LA EMPRESA
Joan Clapés
 
Ad Vice: Ten Tips for Fledgling Digital Marketers
Ad Vice: Ten Tips for Fledgling Digital MarketersAd Vice: Ten Tips for Fledgling Digital Marketers
Ad Vice: Ten Tips for Fledgling Digital Marketers
Jason Theodor
 
anna university automobile engineering unit 1
anna university automobile engineering unit 1 anna university automobile engineering unit 1
anna university automobile engineering unit 1
suresh n
 
Blueprint to Search Engine Success
Blueprint to Search Engine SuccessBlueprint to Search Engine Success
Blueprint to Search Engine Success
iContact
 
AUTOMOBILE BASICS
AUTOMOBILE BASICSAUTOMOBILE BASICS
AUTOMOBILE BASICS
KUCH BHI
 
11 Things to Look For in a Hotel Booking Engine Provider
11 Things to Look For in a Hotel Booking Engine Provider11 Things to Look For in a Hotel Booking Engine Provider
11 Things to Look For in a Hotel Booking Engine Provider
Net Affinity
 
Hardware and Software Architectures for the CELL BROADBAND ENGINE processor
Hardware and Software Architectures for the CELL BROADBAND ENGINE processorHardware and Software Architectures for the CELL BROADBAND ENGINE processor
Hardware and Software Architectures for the CELL BROADBAND ENGINE processor
Slide_N
 
Chapter 1 engine components and classification
Chapter 1   engine components and classificationChapter 1   engine components and classification
Chapter 1 engine components and classification
Hafizkamaruddin
 
Cifras de incidentes de compañías aéreas durante el año 2012
Cifras de incidentes de compañías aéreas durante el año 2012Cifras de incidentes de compañías aéreas durante el año 2012
Cifras de incidentes de compañías aéreas durante el año 2012
Iñaki Ruiz Vazquez
 
Six stroke-engine-presenation
Six stroke-engine-presenationSix stroke-engine-presenation
Six stroke-engine-presenation
gunjan panchal
 
The Endocrine System - Chapter 13
The Endocrine System - Chapter 13The Endocrine System - Chapter 13
The Endocrine System - Chapter 13biol2074
 
The Animated 4 Cycle Internal Combustion Engine
The Animated 4 Cycle Internal Combustion EngineThe Animated 4 Cycle Internal Combustion Engine
The Animated 4 Cycle Internal Combustion Engine
Chris Coggon
 
Industrial relation theories
Industrial relation theoriesIndustrial relation theories
Industrial relation theoriesAniket Verma
 
Cryogenic rocket engine
Cryogenic rocket engineCryogenic rocket engine
Cryogenic rocket engine
guestfadacb
 

Viewers also liked (20)

SQL Server 2014 Mejoras del DB Engine
SQL Server 2014 Mejoras del DB EngineSQL Server 2014 Mejoras del DB Engine
SQL Server 2014 Mejoras del DB Engine
 
Search Engine Optimization
Search Engine OptimizationSearch Engine Optimization
Search Engine Optimization
 
Del SEO a las Redes Sociales
Del SEO a las Redes SocialesDel SEO a las Redes Sociales
Del SEO a las Redes Sociales
 
Ferran calpe b4_lag
Ferran calpe b4_lagFerran calpe b4_lag
Ferran calpe b4_lag
 
Presentacion Blender
Presentacion BlenderPresentacion Blender
Presentacion Blender
 
KRITAL AUDIO ENGINE
KRITAL AUDIO  ENGINE KRITAL AUDIO  ENGINE
KRITAL AUDIO ENGINE
 
MARKETING 2.0 Y REDES SOCIALES EN LA EMPRESA
MARKETING 2.0  Y REDES SOCIALES EN LA EMPRESAMARKETING 2.0  Y REDES SOCIALES EN LA EMPRESA
MARKETING 2.0 Y REDES SOCIALES EN LA EMPRESA
 
Ad Vice: Ten Tips for Fledgling Digital Marketers
Ad Vice: Ten Tips for Fledgling Digital MarketersAd Vice: Ten Tips for Fledgling Digital Marketers
Ad Vice: Ten Tips for Fledgling Digital Marketers
 
anna university automobile engineering unit 1
anna university automobile engineering unit 1 anna university automobile engineering unit 1
anna university automobile engineering unit 1
 
Blueprint to Search Engine Success
Blueprint to Search Engine SuccessBlueprint to Search Engine Success
Blueprint to Search Engine Success
 
AUTOMOBILE BASICS
AUTOMOBILE BASICSAUTOMOBILE BASICS
AUTOMOBILE BASICS
 
11 Things to Look For in a Hotel Booking Engine Provider
11 Things to Look For in a Hotel Booking Engine Provider11 Things to Look For in a Hotel Booking Engine Provider
11 Things to Look For in a Hotel Booking Engine Provider
 
Hardware and Software Architectures for the CELL BROADBAND ENGINE processor
Hardware and Software Architectures for the CELL BROADBAND ENGINE processorHardware and Software Architectures for the CELL BROADBAND ENGINE processor
Hardware and Software Architectures for the CELL BROADBAND ENGINE processor
 
Chapter 1 engine components and classification
Chapter 1   engine components and classificationChapter 1   engine components and classification
Chapter 1 engine components and classification
 
Cifras de incidentes de compañías aéreas durante el año 2012
Cifras de incidentes de compañías aéreas durante el año 2012Cifras de incidentes de compañías aéreas durante el año 2012
Cifras de incidentes de compañías aéreas durante el año 2012
 
Six stroke-engine-presenation
Six stroke-engine-presenationSix stroke-engine-presenation
Six stroke-engine-presenation
 
The Endocrine System - Chapter 13
The Endocrine System - Chapter 13The Endocrine System - Chapter 13
The Endocrine System - Chapter 13
 
The Animated 4 Cycle Internal Combustion Engine
The Animated 4 Cycle Internal Combustion EngineThe Animated 4 Cycle Internal Combustion Engine
The Animated 4 Cycle Internal Combustion Engine
 
Industrial relation theories
Industrial relation theoriesIndustrial relation theories
Industrial relation theories
 
Cryogenic rocket engine
Cryogenic rocket engineCryogenic rocket engine
Cryogenic rocket engine
 

Similar to Them's the Rules - Using a Rules Engine to Wrangle Complexity

Them’s the Rules: Using a Rules Engine to Wrangle Complexity
Them’s the Rules: Using a Rules Engine to Wrangle ComplexityThem’s the Rules: Using a Rules Engine to Wrangle Complexity
Them’s the Rules: Using a Rules Engine to Wrangle Complexity
TechWell
 
Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015
Konstantin Kudryashov
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
Jonathan Wage
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
chartjes
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
Lukas Smith
 
Yves & Zed @ Developer Conference 2013
Yves & Zed @ Developer Conference 2013Yves & Zed @ Developer Conference 2013
Yves & Zed @ Developer Conference 2013
FabianWesnerBerlin
 
Agile data presentation 3 - cambridge
Agile data   presentation 3 - cambridgeAgile data   presentation 3 - cambridge
Agile data presentation 3 - cambridge
Romans Malinovskis
 
Symfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusSymfony 4 Workshop - Limenius
Symfony 4 Workshop - Limenius
Ignacio Martín
 
Yii, frameworks and where PHP is heading to
Yii, frameworks and where PHP is heading toYii, frameworks and where PHP is heading to
Yii, frameworks and where PHP is heading to
Alexander Makarov
 
Gitter marionette deck
Gitter marionette deckGitter marionette deck
Gitter marionette deck
Mike Bartlett
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 Developer
Gary Hockin
 
Modernising Legacy Code
Modernising Legacy CodeModernising Legacy Code
Modernising Legacy Code
SamThePHPDev
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Waters
michael.labriola
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012D
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic Components
Mateusz Tymek
 
Bringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJSBringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJS
Boyan Mihaylov
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Barry Gervin
 
Continously delivering
Continously deliveringContinously delivering
Continously delivering
James Cowie
 

Similar to Them's the Rules - Using a Rules Engine to Wrangle Complexity (20)

Them’s the Rules: Using a Rules Engine to Wrangle Complexity
Them’s the Rules: Using a Rules Engine to Wrangle ComplexityThem’s the Rules: Using a Rules Engine to Wrangle Complexity
Them’s the Rules: Using a Rules Engine to Wrangle Complexity
 
Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Yves & Zed @ Developer Conference 2013
Yves & Zed @ Developer Conference 2013Yves & Zed @ Developer Conference 2013
Yves & Zed @ Developer Conference 2013
 
Agile data presentation 3 - cambridge
Agile data   presentation 3 - cambridgeAgile data   presentation 3 - cambridge
Agile data presentation 3 - cambridge
 
Symfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusSymfony 4 Workshop - Limenius
Symfony 4 Workshop - Limenius
 
Yii, frameworks and where PHP is heading to
Yii, frameworks and where PHP is heading toYii, frameworks and where PHP is heading to
Yii, frameworks and where PHP is heading to
 
Gitter marionette deck
Gitter marionette deckGitter marionette deck
Gitter marionette deck
 
Boston 16 03
Boston 16 03Boston 16 03
Boston 16 03
 
Backbone Basics with Examples
Backbone Basics with ExamplesBackbone Basics with Examples
Backbone Basics with Examples
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 Developer
 
Modernising Legacy Code
Modernising Legacy CodeModernising Legacy Code
Modernising Legacy Code
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Waters
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic Components
 
Bringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJSBringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJS
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
 
Continously delivering
Continously deliveringContinously delivering
Continously delivering
 

Recently uploaded

Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
Jelle | Nordend
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 

Recently uploaded (20)

Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 

Them's the Rules - Using a Rules Engine to Wrangle Complexity

  • 1. Them’s the Rules by Micah Breedlove Using a Rules Engine to Wrangle Complexity
  • 2. PHP Dev since ‘98 Symfony Evangelist @druid628 http://micah.breedlove.in/ Sr. Developer / Team Lead @ iostudio Who is this guy?
  • 4. Ruler Written by Justin Hileman(BobTheCow) GitHub: https://github.com/bobthecow/Ruler Packagist: ruler/ruler
  • 6. Conditional Logic “hypothetical logic (of a proposition) consisting of two component propositions... so that the proposition is false only when the antecedent is true and the consequent false.” How we handle the unknown.
  • 7. Rules Engines “A business rules engine is a software system that executes one or more business rules in a runtime production environment.” “An added layer of complexity to carry out, often complicated, business logic of the application” in other words...
  • 9. Examples Discounts on products purchased Combination of products Subscribed services Additional Fees Geographical assessment Risk assessment
  • 10. What is wrong with this? if ( $obj->getName() == ‘abc’) { } elseif ($obj->getName() == ‘def’) { } elseif ($obj->getName() == ‘ghi’) { } elseif ($obj->getName() == ‘jkl’ ) { } elseif ($obj->getName() == ‘mno’ ) { } elseif ($obj->getName() == ‘pqr’ && $obj->getClient()->getCategory() !== ‘hotChkn’) { }elseif ($obj->getName() == ‘Hg(CNO)2’ && $obj->getClientKey() == ‘tuco’){ }elseif ($obj->getName() == ‘blueSky’ && $obj->getClientKey() == ‘losPollosHermanos’) { } elseif ($obj->getName() == ‘blueSky’ && $obj->getClientKey() == ‘heisenberg’){}
  • 11. ...
  • 12. Should be kept trimmed, maintained and under control Or else... Pandemonium Ensues Conditional statements are like Kudzu
  • 13. Fixable? Something to … Abstractly handle multiple conditions With Minimal conditional logic and is Reusable
  • 14. Simplifies a block into a generic block Support more than a simple/singular condition Abstraction
  • 15. Minimize Conditional Logic Drop the ever-building conditionals Replace with smaller defined block
  • 16. Reusability Ability to support all existing conditions Individual rules can be evaluated in other RuleSets
  • 17. The saga begins… if ($bond->getClient()== ‘client1’ && $event->getName() == ‘bond.create’) { $this->calculateClient1BondAdjustments($bond); } elseif ($bond->getClient() == ‘client1’ && $event->getName() == ‘payment.made’) { $this->calculateClient1Payment($bond, $payment); } elseif ($bond->getClient() == ‘client2’ && $event->getName() == ‘bond.create’) { $this->calculateClient2BondAdjustments($bond); } elseif ($bond->getClient() == ‘client3’ && $event->getName() == ‘bond.create’) { $this->calculateClient3BondAdjustments($bond); } ...
  • 18. What We Need If a Bond is made in Collegedale A $25 fee should be assessed
  • 19. $rule = $ruleFactory->getBondRules(); $clientRule = [ ‘district’ => ‘collegedale’, ‘district_fee’ => ‘25’, ‘fee_adjustment’ => ‘+’ ]; $context = new Context([ ‘bond_district’ => $bond->getDistrict(), ‘district’ => $clientRule[‘district’], ‘district_fee’ => $clientRule[‘district_fee’], ‘fee_adjustment’ => $clientRule[‘’fee_adjustment’] ]); $rule->execute($context); Rule Elements
  • 20. Ruler - Elements of the Equation 3 Parts Context Rule Execution/Evaluation
  • 21. Context - All Applicable Data Variable Data: ‘bond_district’ => ‘collegedale’, Control Data: ‘district’ => ‘collegedale’, ‘district_fee’ => ‘25’, ‘fee_adjustment’ => ‘+’ Variable Data Request User Specific (includes session) Control Data Specific to the Rule
  • 22. Rule $rule = $rb->create( $rb['bond_district']->EqualTo($rb['district']) ); How the Context Stacks Up How to evaluate the data What to evaluate Variable Data: ‘bond_district’ => ‘collegedale’, Control Data: ‘district’ => ‘collegedale’, ‘district_fee’ => ‘25’, ‘fee_adjustment’ => ‘+’
  • 23. Rule (cont.) Compound Rules $rule = $rb->create( $rb->LogicalAnd( $rb['bond_district']->EqualTo($rb['district']), $rb['bond_amount']->GreaterThan('20000') ) );
  • 24. Evaluation/Execution Evaluate - (boolean) Did it meet the condition? Execution - (void) If it’s true do something
  • 25. Evaluation Example Rule: $rule = $rb->create( $rb['bond_district']->EqualTo($rb['district']) ); $status = $rule->evaluate($context); echo $status; // true Control Data: ‘district’ => ‘collegedale’, ‘district_fee’ => ‘25’, ‘fee_adjustment’ => ‘+’ Variable Data: ‘bond_district’ => ‘collegedale’
  • 26. Execution Example $rule->execute($context); // output: An additional mileage fee will be charged. Control Data: ‘district’ => ‘collegedale’, ‘district_fee’ => ‘25’, ‘fee_adjustment’ => ‘+’ Variable Data: ‘bond_district’ => ‘collegedale’ Rule: $rule = $rb->create( $rb['bond_district']->EqualTo($rb['district']), function() { echo 'An additional mileage fee will be charged.'; } );
  • 27. if ($bond->getClient()== ‘client1’ && $event->getName() == ‘bond.create’) { $this->calculateClient1BondAdjustments($bond); } elseif ($bond->getClient() == ‘client1’ && $event->getName() == ‘payment.made’) { $this->calculateClient1Payment($bond, $payment); } elseif ($bond->getClient() == ‘client2’ && $event->getName() == ‘bond.create’) { $this->calculateClient2BondAdjustments($bond); } elseif ($bond->getClient() == ‘client3’ && $event->getName() == ‘bond.create’) { $this->calculateClient3BondAdjustments($bond); } ... Finally this…
  • 28. ...becomes this $ruleObject = $rulesRepo->get($event->getName()); // assume bond.create $context = $ruleObject->getContext(); $context[‘bond’] = $bond; $rule = $ruleObject->getRule(); $rule->execute($context); // one rule to rule them all
  • 33. citations Jesse (Breaking Bad) - http://replygif.net/i/1323.gif Kudzu - http://2.bp.blogspot.com/_RTswKzWDHeM/SE198zJTgzI/AAAAAAAAA80/ZKj4haQbiSE/s320/kudzu+house.jpg MC Hammer - http://24.media.tumblr.com/26d1484f43ff55401f8ead9d03432bb9/tumblr_moctg0LbmC1sn8pc2o1_400.gif