From Event to Action: Accelerate Your Decision Making with Real-Time Automation
New design patterns
1. Strategy Pattern
•Design re-usable code without using inheritance
•Different behaviors required for the same method (e.g. weapon behavior for
characters in a game)
Problem
2. Strategy Pattern
•Design re-usable code without using inheritance
•Different behaviors required for the same method (e.g. weapon behavior for
characters in a game)
Problem
•Encapsulate data and behaviors in classes
•Identify behaviors and create interfaces for each
•Create behavior classes that implement each behavior interface
Solution
3. Strategy Pattern
•Design re-usable code without using inheritance
•Different behaviors required for the same method (e.g. weapon behavior for
characters in a game)
Problem
•Encapsulate data and behaviors in classes
•Identify behaviors and create interfaces for each
•Create behavior classes that implement each behavior interface
Solution
•Loosely coupling objects via interfaces is more independent and easier to modify
•Encapsulation hides internal behavior of objects (can change behavior without
impacting how it is used
Consequences (benefits)
4. Strategy Pattern
•Design re-usable code without using inheritance
•Different behaviors required for the same method (e.g. weapon behavior for
characters in a game)
Problem
•Encapsulate data and behaviors in classes
•Identify behaviors and create interfaces for each
•Create behavior classes that implement each behavior interface
Solution
•Loosely coupling objects via interfaces is more independent and easier to modify
•Encapsulation hides internal behavior of objects (can change behavior without
impacting how it is used
Consequences (benefits)
•Better understanding of the power of object oriented software design
•More capable of designing manageable/maintainable code
Key Learnings
5. Strategy Pattern Example
Character
Abstract Class
fight()
useWeapon()
setDamage()
eat()
King
fight()
useWeapon()
setWeaponBehavior()
setFightBehavior()
setEatBehavior()
setDamage()
eat()
setWeaponBehavior()
setFightBehavior()
setEatBehavior()
FootSoldier
fight()
useWeapon()
setDamage()
eat()
setWeaponBehavior()
setFightBehavior()
setEatBehavior()
Knight
fight()
useWeapon()
setDamage()
eat()
setWeaponBehavior()
setFightBehavior()
setEatBehavior()
<<Interface>>
FightBehavior
fight()
WeaponBehavior
Abstract Class
int damage
useWeapon()
setDamage()
EatBehavior
Abstract Class
int damage
float poundsFood
String utensil
String container
String foodType
eat()
AggresiveFight
fight()
PassiveFight
fight()