SlideShare a Scribd company logo
1 of 68
Download to read offline
AGENDA
Strategy Pattern
Template Method
State Pattern
Observer Pattern
Command Pattern
Iterator Pattern
Behavioral Design Patterns
Behavioral Design Patterns
AGENDA
Problem
Solution
Structure
PHP Code
Pros & Cons
Intent
STRATEGY PATTERN
Duck simulation app
Strategy Pattern
Problem
Strategy Pattern
Problem
Strategy Pattern
Problem
Strategy Pattern
Problem
Strategy Pattern
Problem
Strategy Pattern
Solution
Strategy Pattern
Solution
Strategy Pattern
Structure
Strategy Pattern
PHP Code
Hot swapping algorithms at runtime.
Isolates the code of the algorithms from
the other classes.
Replaces inheritance with composition.
Follows the Open/Closed Principle.
Strategy Pattern
Pros & Cons
Increases overall code complexity by
creating multiple additional classes.
Client must be aware of the differences
between strategies to pick a proper one.
Strategy lets you:
Define a family of algorithms.
Encapsulate each one.
Make them interchangeable.
Strategy lets the algorithm:
Vary independently from the clients that use it.
Strategy Pattern
Intent
TEMPLATE METHOD PATTERN
Template Method
Problem
Template Method
Problem
Solution
Template Method
Solution
Template Method
Structure
Template Method
PHP Code
Template Method
Helps to eliminate code duplication.
Flexibility lets subclasses decide how
to implement steps in an algorithm.
Pros & Cons
You are limited with a skeleton of an
existing algorithm.
Built in inheritance rather than composition.
Template methods tend to be harder to
maintain the more steps they have.
Template Method
Template Method lets you:
define the skeleton of an algorithm
Allow subclasses to:
redefine certain steps of the algorithm without changing its structure.
Intent
Template Method
STATE PATTERN
State Pattern
Problem
State Pattern
Problem
State Pattern
Problem
State Pattern
Problem
Solution
State Pattern
Solution
State Pattern
Solution
State Pattern
Structure
Iterator PatternState Pattern
PHP Code
State Pattern
Eliminates state machine conditionals.
Organizes the code related to
particular states into separate classes.
Simplifies the code of the context.
Pros & Cons
Can be an overkill if a state machine has
only a few states or rarely changes.
State Pattern
State pattern allows an object to:
alter its behavior when its internal state changes.
The object will appear to change its class.
Intent
State Pattern
OBSERVER PATTERN
Observer Pattern
Problem
Observer Pattern
Problem
Observer Pattern
Problem
Observer Pattern
Solution
Observer Pattern
Solution
Observer Pattern
Solution
Observer Pattern
Solution
Observer Pattern
Structure
Strategy Pattern
PHP Code
Observer Pattern
Subject is not coupled to concrete
observer classes.
You can register and remove objects
dynamically.
Follows the Open/Closed Principle.
Strategy Pattern
Pros & Cons
Observers are notified in random order.
If not used carefully, It can add unnecessary
complexity
Observer Pattern
Observer lets you:
define a one-to-many dependency between objects, so that when one object changes state,
all its dependents are notified and updated automatically.
Strategy Pattern
Intent
Observer Pattern
COMMAND PATTERN
Command Pattern
Problem
Command Pattern
Problem
Command Pattern
Solution
Command Pattern
Solution
Command Pattern
Solution
Command Pattern
Solution
Observer Pattern
Structure
Command Pattern
PHP Code
Command Pattern
Decouples classes that invoke operations from classes
that perform them.
Allows reversal (undo) of operations.
Allows deferred execution of operations.
Allows assembling simple commands into larger ones.
Follows the Open/Closed Principle.
Strategy Pattern
Pros & Cons
Increases overall code complexity by creating
multiple additional classes.
Observer PatternCommand Pattern
Command lets you:
turn a request into stand-alone object, which can be used to parametrize objects with
different requests and support undoable operations.
Intent
Command Pattern
ITERATOR PATTERN
Iterator Pattern
Problem
Iterator Pattern
Problem
Solution
Iterator Pattern
Solution
Iterator Pattern
Structure
Iterator Pattern
PHP Code
Iterator Pattern
Decouples the collection's code.
Provides multiple ways to traverse
the same data structure.
Allows parallel traversing of the same
collection.
Pros & Cons
Can be overkill for programs that work
with simple collections.
Iterator Pattern
Iterator pattern lets you:
access the elements of an aggregate object sequentially
Without:
exposing its underlying representation.
Intent
Iterator Pattern
Behavioral design patterns presentation

More Related Content

What's hot

The "Evils" of Optimization
The "Evils" of OptimizationThe "Evils" of Optimization
The "Evils" of Optimization
BlackRabbitCoder
 
Testcase definition
Testcase definitionTestcase definition
Testcase definition
Oana Feidi
 
Testcase definition
Testcase definitionTestcase definition
Testcase definition
Oana Feidi
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
Jason Townsend, MBA
 

What's hot (19)

Chapter 09
Chapter 09Chapter 09
Chapter 09
 
Effective Unit Test Style Guide
Effective Unit Test Style GuideEffective Unit Test Style Guide
Effective Unit Test Style Guide
 
Boundary value analysis and equivalence partitioning
Boundary value analysis and equivalence partitioningBoundary value analysis and equivalence partitioning
Boundary value analysis and equivalence partitioning
 
Expressive Testing ...and your Code For Free?
Expressive Testing ...and your Code For Free?Expressive Testing ...and your Code For Free?
Expressive Testing ...and your Code For Free?
 
The "Evils" of Optimization
The "Evils" of OptimizationThe "Evils" of Optimization
The "Evils" of Optimization
 
Best Practices of Software Development
Best Practices of Software DevelopmentBest Practices of Software Development
Best Practices of Software Development
 
L05 Design Patterns
L05 Design PatternsL05 Design Patterns
L05 Design Patterns
 
Testcase definition
Testcase definitionTestcase definition
Testcase definition
 
Testcase definition
Testcase definitionTestcase definition
Testcase definition
 
Debugging in .Net
Debugging in .NetDebugging in .Net
Debugging in .Net
 
Sorfware engineering presentation (software testing)
Sorfware engineering presentation (software testing)Sorfware engineering presentation (software testing)
Sorfware engineering presentation (software testing)
 
Strategy pattern
Strategy patternStrategy pattern
Strategy pattern
 
Combating software entropy 2-roc1-
Combating software entropy 2-roc1-Combating software entropy 2-roc1-
Combating software entropy 2-roc1-
 
Error Correction Techniques
Error Correction TechniquesError Correction Techniques
Error Correction Techniques
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
 
Black box testing - SlideShare jayed hossain jibon
Black box testing - SlideShare  jayed hossain jibonBlack box testing - SlideShare  jayed hossain jibon
Black box testing - SlideShare jayed hossain jibon
 
Test setup methods in Salesforce Apex Class
Test setup methods in Salesforce Apex ClassTest setup methods in Salesforce Apex Class
Test setup methods in Salesforce Apex Class
 
Design Test Case Technique (Equivalence partitioning And Boundary value analy...
Design Test Case Technique (Equivalence partitioning And Boundary value analy...Design Test Case Technique (Equivalence partitioning And Boundary value analy...
Design Test Case Technique (Equivalence partitioning And Boundary value analy...
 

Similar to Behavioral design patterns presentation

Design Patterns
Design PatternsDesign Patterns
Design Patterns
soms_1
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
danhaley45372
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 

Similar to Behavioral design patterns presentation (20)

Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기
 
Design pattern
Design patternDesign pattern
Design pattern
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
The Nature Of Patterns
The Nature Of PatternsThe Nature Of Patterns
The Nature Of Patterns
 
DesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatternsDesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatterns
 
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design PatternsNina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
 
Code Metrics
Code MetricsCode Metrics
Code Metrics
 
Introduction To Design Patterns
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patterns
 
ALMOsT.js: an Agile Model to Model and Model to Text Transformation Framework
ALMOsT.js: an Agile Model to Model and Model to Text Transformation FrameworkALMOsT.js: an Agile Model to Model and Model to Text Transformation Framework
ALMOsT.js: an Agile Model to Model and Model to Text Transformation Framework
 
L03 Design Patterns
L03 Design PatternsL03 Design Patterns
L03 Design Patterns
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
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...
 
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)
 

Behavioral design patterns presentation