SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Downloaden Sie, um offline zu lesen
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
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
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)
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
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()

Weitere ähnliche Inhalte

Ähnlich wie New design patterns

Google App Engine - exploiting limitations
Google App Engine - exploiting limitationsGoogle App Engine - exploiting limitations
Google App Engine - exploiting limitations
Tomáš Holas
 
8 oo approach&uml-23_feb
8 oo approach&uml-23_feb8 oo approach&uml-23_feb
8 oo approach&uml-23_feb
Raj Shah
 
332 ch07
332 ch07332 ch07
332 ch07
YaQ10
 

Ähnlich wie New design patterns (20)

Software Design
Software DesignSoftware Design
Software Design
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design pattern
Design patternDesign pattern
Design pattern
 
MongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combinationMongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combination
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 
Ooad ch 2
Ooad ch 2Ooad ch 2
Ooad ch 2
 
Advanced CSS Troubleshooting
Advanced CSS TroubleshootingAdvanced CSS Troubleshooting
Advanced CSS Troubleshooting
 
InfectNet Technical
InfectNet TechnicalInfectNet Technical
InfectNet Technical
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Introduction
IntroductionIntroduction
Introduction
 
Google App Engine - exploiting limitations
Google App Engine - exploiting limitationsGoogle App Engine - exploiting limitations
Google App Engine - exploiting limitations
 
Software enginering.group-no-11 (1)
Software enginering.group-no-11 (1)Software enginering.group-no-11 (1)
Software enginering.group-no-11 (1)
 
8 oo approach&uml-23_feb
8 oo approach&uml-23_feb8 oo approach&uml-23_feb
8 oo approach&uml-23_feb
 
Design Patterns - GOF
Design Patterns - GOFDesign Patterns - GOF
Design Patterns - GOF
 
Ooad ch 1_2
Ooad ch 1_2Ooad ch 1_2
Ooad ch 1_2
 
332 ch07
332 ch07332 ch07
332 ch07
 
ER diagram slides for datanase stujdy-1.pdf
ER diagram slides for datanase stujdy-1.pdfER diagram slides for datanase stujdy-1.pdf
ER diagram slides for datanase stujdy-1.pdf
 
CS6201 Software Reuse - Design Patterns
CS6201 Software Reuse - Design PatternsCS6201 Software Reuse - Design Patterns
CS6201 Software Reuse - Design Patterns
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
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()