SlideShare a Scribd company logo
Know me well to get your goals! Session # 5 MuhamadHesham
Agenda Why design patterns? Dynamic behaviors everywhere Our pattern exposed Applicability Design Changes Why all of this?
Where are we? Great Software 1. Make sure your software does what customer wants it to do
Where are we? Great Software 1. Make sure your software does what customer wants it to do 2.Apply basic OO princibles to add more flexibility
Where are we? Great Software 1. Make sure your software does what customer wants it to do 2.Apply basic OO princibles to add more flexibility 3.Strive for maintainability and reusable design
Guess what? “The one constant in software development”
Guess what? “The one constant in software development” CHANGE
Why Design Patterns? Job Requirements
Pocket Money You: Dad, I need pocket money.
Pocket Money Angry Dad
Pocket Money Troubled Dad
Pocket Money Happy Dad
Pepsi Machine
Pepsi State Machine Out of Pepsi No Money insert money pepsi > 0 eject money pepsi = 0 Pepsi Sold Has Money order pepsi
Platformer Game
Enemy State Machine reach cliff after a while Running Idle
Coding by Sense® /// <summary> /// Paces back and forth along a platform, waiting at either end. /// </summary> public void Update(GameTimegameTime) {           if (State == EnemyState.Idle) 	{ 		// If time-out go-to state Running 		// Else wait for some amount of time             	} else if (State == EnemyState.Running)             	{  // Update enemy position 		 // If reach cliff go-to state Idle 	} }
Messenger
Messenger State Machine Available Offline sign in available busy away available Away Busy away busy All states are connected to offline via sign out
Coding by Sense® /// <summary> /// Occurs when a remote client sends a message /// </summary> public void OnMessageSent(Message msg) {           if (State == MessengerState.Aways) 	{             	} else if (State == MessengerState.Busy)             	{ 	} 	... 	… }
Coding by Sense® /// <summary> /// Occurs when a remote client sends a message /// </summary> public void OnContactSignIn(Message msg) {           if (State == MessengerState.Aways) 	{             	} else if (State == MessengerState.Busy)             	{ 	} 	... 	… }
Coding by Sense® /// <summary> /// Occurs when a remote client sends a message /// </summary> public void OnNudge(Message msg) {           if (State == MessengerState.Aways) 	{             	} else if (State == MessengerState.Busy)             	{ 	} 	... 	… }
Our Code Smells Bad Violates Open Closed Principle. Further additions may cause bugs. State transitions are buried between if-else.
Exploring the pattern Let’s Google it!
Explaining the pattern Pattern class diagram
Explaining the pattern Participants Context defines the interface of interest to clients.  maintains an instance of a ConcreteState subclass that defines the current state. State defines an interface for encapsulating the behavior associated with a particular state of the Context. ConcreteState subclasses each subclass implements a behavior associated with a state of the Context.
Explaining the pattern Example
How they interact? Set Initial State Context Context Foo Foo(                       ) Current-State Context
Applicability What are the symptoms should I take care of ?
Applicability But take care! OVER DESIGN nightmare
Design Challenges Who defines the state transitions? (Classes Dependency)
Design Challenges Creatingand destroyingState objects (Memory Management)
Further Reading What’s Next State Pattern: Chapter 10 in Head First Strategy Pattern: Chapter 1 in Head First GoF: Behavioral Pattern Section Section: Enhance way of drawing shapes
Finally Where are our scientists? HF & DS authors. Taha & Elmasri. Previous: Algorithm, Algebra, 1,2,3, Camera, NASA. Hospital. Nueclar scientist. Stat. What about efforts? Thomas Edison. Reading books. EbnMakhld. Quotes. Why all of this? “No pain, no gain” Anonymous.  “لا يُستطاع العلم براحة الجسم” يحى بن كثير “My inventions comes from 2% inspiration and 98% of efforts” Thomas Edison. “Science is what we understand well enough to explain to a computer. Art is everything else we do” Donald Knuth.
Thank you ... Questions? mhesham.fcis@gmail.com

More Related Content

Viewers also liked

Product Management Portfolio
Product Management PortfolioProduct Management Portfolio
Product Management Portfolio
Steve Orme
 
Design Patterns Summer Course 2009-2010 - Session#3
Design Patterns Summer Course 2009-2010 - Session#3Design Patterns Summer Course 2009-2010 - Session#3
Design Patterns Summer Course 2009-2010 - Session#3
Muhamad Hesham
 
Design Patterns Summer Course 2010-2011 - Session#2
Design Patterns Summer Course 2010-2011 - Session#2Design Patterns Summer Course 2010-2011 - Session#2
Design Patterns Summer Course 2010-2011 - Session#2
Muhamad Hesham
 
[K Engine] Intorduction To Machine Planning, A Case Based Approach
[K Engine] Intorduction To Machine Planning, A Case Based Approach[K Engine] Intorduction To Machine Planning, A Case Based Approach
[K Engine] Intorduction To Machine Planning, A Case Based Approach
Muhamad Hesham
 
Smart leaven technologies_corporate_presentation_short_4
Smart leaven technologies_corporate_presentation_short_4Smart leaven technologies_corporate_presentation_short_4
Smart leaven technologies_corporate_presentation_short_4
Ganesh Shevade
 
NTP Software Jan 2012 Monthly Meeting IPC Presentation
NTP Software Jan 2012 Monthly Meeting IPC PresentationNTP Software Jan 2012 Monthly Meeting IPC Presentation
NTP Software Jan 2012 Monthly Meeting IPC Presentation
Muhamad Hesham
 
1st Seminar- Intelligent Agent for Medium-Level Artificial Intelligence in Re...
1st Seminar- Intelligent Agent for Medium-Level Artificial Intelligence in Re...1st Seminar- Intelligent Agent for Medium-Level Artificial Intelligence in Re...
1st Seminar- Intelligent Agent for Medium-Level Artificial Intelligence in Re...
Muhamad Hesham
 
On writing well
On writing wellOn writing well
On writing well
irepdaronx
 

Viewers also liked (8)

Product Management Portfolio
Product Management PortfolioProduct Management Portfolio
Product Management Portfolio
 
Design Patterns Summer Course 2009-2010 - Session#3
Design Patterns Summer Course 2009-2010 - Session#3Design Patterns Summer Course 2009-2010 - Session#3
Design Patterns Summer Course 2009-2010 - Session#3
 
Design Patterns Summer Course 2010-2011 - Session#2
Design Patterns Summer Course 2010-2011 - Session#2Design Patterns Summer Course 2010-2011 - Session#2
Design Patterns Summer Course 2010-2011 - Session#2
 
[K Engine] Intorduction To Machine Planning, A Case Based Approach
[K Engine] Intorduction To Machine Planning, A Case Based Approach[K Engine] Intorduction To Machine Planning, A Case Based Approach
[K Engine] Intorduction To Machine Planning, A Case Based Approach
 
Smart leaven technologies_corporate_presentation_short_4
Smart leaven technologies_corporate_presentation_short_4Smart leaven technologies_corporate_presentation_short_4
Smart leaven technologies_corporate_presentation_short_4
 
NTP Software Jan 2012 Monthly Meeting IPC Presentation
NTP Software Jan 2012 Monthly Meeting IPC PresentationNTP Software Jan 2012 Monthly Meeting IPC Presentation
NTP Software Jan 2012 Monthly Meeting IPC Presentation
 
1st Seminar- Intelligent Agent for Medium-Level Artificial Intelligence in Re...
1st Seminar- Intelligent Agent for Medium-Level Artificial Intelligence in Re...1st Seminar- Intelligent Agent for Medium-Level Artificial Intelligence in Re...
1st Seminar- Intelligent Agent for Medium-Level Artificial Intelligence in Re...
 
On writing well
On writing wellOn writing well
On writing well
 

Similar to Design Patterns Summer Course 2010-2011 - Session#1

Try the monad!
Try the monad!Try the monad!
Try the monad!
Luis Muniz
 
Contact management system
Contact management systemContact management system
Contact management system
SHARDA SHARAN
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practices
floydophone
 
Brownfield Domain Driven Design
Brownfield Domain Driven DesignBrownfield Domain Driven Design
Brownfield Domain Driven Design
Nicolò Pignatelli
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
elliando dias
 
Presentation on design pattern software project lll
 Presentation on design pattern  software project lll  Presentation on design pattern  software project lll
Presentation on design pattern software project lll
Uchiha Shahin
 
Modern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptxModern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptx
Md Shamsul Arafin Mahtab
 
JavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern ImplementationJavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern Implementation
davejohnson
 
MWLUG 2014: ATLUG Comes To You
MWLUG 2014: ATLUG Comes To YouMWLUG 2014: ATLUG Comes To You
MWLUG 2014: ATLUG Comes To You
Peter Presnell
 
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
HYS Enterprise
 
Operationalizing Clojure Confidently
Operationalizing Clojure ConfidentlyOperationalizing Clojure Confidently
Operationalizing Clojure Confidently
Prasanna Gautam
 
Selenium web driver | java
Selenium web driver | javaSelenium web driver | java
Selenium web driver | java
Rajesh Kumar
 
Functional programming in TypeScript
Functional programming in TypeScriptFunctional programming in TypeScript
Functional programming in TypeScript
binDebug WorkSpace
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
Jose Manuel Pereira Garcia
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
Cherimay Batallones
 
Building a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one weekBuilding a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one week
Dr. Felix Raab
 
Chatbot Tutorial - Create your first bot with Xatkit
Chatbot Tutorial - Create your first bot with Xatkit Chatbot Tutorial - Create your first bot with Xatkit
Chatbot Tutorial - Create your first bot with Xatkit
Jordi Cabot
 
Choose flutter
Choose flutterChoose flutter
Choose flutter
SamuelAdetunji2
 
Douglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsDouglas Crockford Presentation Goodparts
Douglas Crockford Presentation Goodparts
Ajax Experience 2009
 
Building a multi touch enabled windows 7 point of sale system
Building a multi touch enabled windows 7 point of sale systemBuilding a multi touch enabled windows 7 point of sale system
Building a multi touch enabled windows 7 point of sale system
Chris Eargle
 

Similar to Design Patterns Summer Course 2010-2011 - Session#1 (20)

Try the monad!
Try the monad!Try the monad!
Try the monad!
 
Contact management system
Contact management systemContact management system
Contact management system
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practices
 
Brownfield Domain Driven Design
Brownfield Domain Driven DesignBrownfield Domain Driven Design
Brownfield Domain Driven Design
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
Presentation on design pattern software project lll
 Presentation on design pattern  software project lll  Presentation on design pattern  software project lll
Presentation on design pattern software project lll
 
Modern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptxModern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptx
 
JavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern ImplementationJavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern Implementation
 
MWLUG 2014: ATLUG Comes To You
MWLUG 2014: ATLUG Comes To YouMWLUG 2014: ATLUG Comes To You
MWLUG 2014: ATLUG Comes To You
 
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
 
Operationalizing Clojure Confidently
Operationalizing Clojure ConfidentlyOperationalizing Clojure Confidently
Operationalizing Clojure Confidently
 
Selenium web driver | java
Selenium web driver | javaSelenium web driver | java
Selenium web driver | java
 
Functional programming in TypeScript
Functional programming in TypeScriptFunctional programming in TypeScript
Functional programming in TypeScript
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
Building a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one weekBuilding a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one week
 
Chatbot Tutorial - Create your first bot with Xatkit
Chatbot Tutorial - Create your first bot with Xatkit Chatbot Tutorial - Create your first bot with Xatkit
Chatbot Tutorial - Create your first bot with Xatkit
 
Choose flutter
Choose flutterChoose flutter
Choose flutter
 
Douglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsDouglas Crockford Presentation Goodparts
Douglas Crockford Presentation Goodparts
 
Building a multi touch enabled windows 7 point of sale system
Building a multi touch enabled windows 7 point of sale systemBuilding a multi touch enabled windows 7 point of sale system
Building a multi touch enabled windows 7 point of sale system
 

Recently uploaded

คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Diana Rendina
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 

Recently uploaded (20)

คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 

Design Patterns Summer Course 2010-2011 - Session#1

  • 1. Know me well to get your goals! Session # 5 MuhamadHesham
  • 2. Agenda Why design patterns? Dynamic behaviors everywhere Our pattern exposed Applicability Design Changes Why all of this?
  • 3. Where are we? Great Software 1. Make sure your software does what customer wants it to do
  • 4. Where are we? Great Software 1. Make sure your software does what customer wants it to do 2.Apply basic OO princibles to add more flexibility
  • 5. Where are we? Great Software 1. Make sure your software does what customer wants it to do 2.Apply basic OO princibles to add more flexibility 3.Strive for maintainability and reusable design
  • 6. Guess what? “The one constant in software development”
  • 7. Guess what? “The one constant in software development” CHANGE
  • 8. Why Design Patterns? Job Requirements
  • 9. Pocket Money You: Dad, I need pocket money.
  • 14. Pepsi State Machine Out of Pepsi No Money insert money pepsi > 0 eject money pepsi = 0 Pepsi Sold Has Money order pepsi
  • 16. Enemy State Machine reach cliff after a while Running Idle
  • 17. Coding by Sense® /// <summary> /// Paces back and forth along a platform, waiting at either end. /// </summary> public void Update(GameTimegameTime) { if (State == EnemyState.Idle) { // If time-out go-to state Running // Else wait for some amount of time } else if (State == EnemyState.Running) { // Update enemy position // If reach cliff go-to state Idle } }
  • 19. Messenger State Machine Available Offline sign in available busy away available Away Busy away busy All states are connected to offline via sign out
  • 20. Coding by Sense® /// <summary> /// Occurs when a remote client sends a message /// </summary> public void OnMessageSent(Message msg) { if (State == MessengerState.Aways) { } else if (State == MessengerState.Busy) { } ... … }
  • 21. Coding by Sense® /// <summary> /// Occurs when a remote client sends a message /// </summary> public void OnContactSignIn(Message msg) { if (State == MessengerState.Aways) { } else if (State == MessengerState.Busy) { } ... … }
  • 22. Coding by Sense® /// <summary> /// Occurs when a remote client sends a message /// </summary> public void OnNudge(Message msg) { if (State == MessengerState.Aways) { } else if (State == MessengerState.Busy) { } ... … }
  • 23. Our Code Smells Bad Violates Open Closed Principle. Further additions may cause bugs. State transitions are buried between if-else.
  • 24. Exploring the pattern Let’s Google it!
  • 25. Explaining the pattern Pattern class diagram
  • 26. Explaining the pattern Participants Context defines the interface of interest to clients. maintains an instance of a ConcreteState subclass that defines the current state. State defines an interface for encapsulating the behavior associated with a particular state of the Context. ConcreteState subclasses each subclass implements a behavior associated with a state of the Context.
  • 28. How they interact? Set Initial State Context Context Foo Foo( ) Current-State Context
  • 29. Applicability What are the symptoms should I take care of ?
  • 30. Applicability But take care! OVER DESIGN nightmare
  • 31. Design Challenges Who defines the state transitions? (Classes Dependency)
  • 32. Design Challenges Creatingand destroyingState objects (Memory Management)
  • 33. Further Reading What’s Next State Pattern: Chapter 10 in Head First Strategy Pattern: Chapter 1 in Head First GoF: Behavioral Pattern Section Section: Enhance way of drawing shapes
  • 34. Finally Where are our scientists? HF & DS authors. Taha & Elmasri. Previous: Algorithm, Algebra, 1,2,3, Camera, NASA. Hospital. Nueclar scientist. Stat. What about efforts? Thomas Edison. Reading books. EbnMakhld. Quotes. Why all of this? “No pain, no gain” Anonymous. “لا يُستطاع العلم براحة الجسم” يحى بن كثير “My inventions comes from 2% inspiration and 98% of efforts” Thomas Edison. “Science is what we understand well enough to explain to a computer. Art is everything else we do” Donald Knuth.
  • 35. Thank you ... Questions? mhesham.fcis@gmail.com

Editor's Notes

  1. CollaborationsContext delegates state-specific requests to the current ConcreteState object. A context may pass itself as an argument to the State object handling the request. This lets the State object access the context if necessary. Context is the primary interface for clients. Clients can configure a context with State objects. Once a context is configured, its clients don&apos;t have to deal with the State objects directly. Either Context or the ConcreteState subclasses can decide which state succeeds another and under what circumstances.
  2. CollaborationsContext delegates state-specific requests to the current ConcreteState object. A context may pass itself as an argument to the State object handling the request. This lets the State object access the context if necessary. Context is the primary interface for clients. Clients can configure a context with State objects. Once a context is configured, its clients don&apos;t have to deal with the State objects directly. Either Context or the ConcreteState subclasses can decide which state succeeds another and under what circumstances.
  3. Use the State pattern in either of the following cases:An object&apos;s behavior depends on its state, and it must change its behavior at run-time depending on that state. Operations have large, multipart conditional statements that depend on the object&apos;s state. This state is usually represented by one or more enumerated constants. Often, several operations will contain this same conditional structure. The State pattern puts each branch of the conditional in a separate class. This lets you treat the object&apos;s state as an object in its own right that can vary independently from other objects.
  4. Use the State pattern in either of the following cases:An object&apos;s behavior depends on its state, and it must change its behavior at run-time depending on that state. Operations have large, multipart conditional statements that depend on the object&apos;s state. This state is usually represented by one or more enumerated constants. Often, several operations will contain this same conditional structure. The State pattern puts each branch of the conditional in a separate class. This lets you treat the object&apos;s state as an object in its own right that can vary independently from other objects.
  5. Who defines the state transitions? The State pattern does not specify which participant defines the criteria for state transitions. If the criteria are fixed, then they can be implemented entirely in the Context. It is generally more flexible and appropriate, however, to let the State subclasses themselves specify their successor state and when to make the transition. This requires adding an interface to the Context that lets State objects set the Context&apos;s current state explicitly. Decentralizing the transition logic in this way makes it easy to modify or extend the logic by defining new State subclasses. A disadvantage of decentralization is that one State subclass will have knowledge of at least one other, which introduces implementation dependencies between subclasses.
  6. Creating and destroying State objects. A common implementation trade-off worth considering is whether (1) to create State objects only when they are needed and destroy them thereafter versus (2) creating them ahead of time and never destroying them. The first choice is preferable when the states that will be entered aren&apos;t known at run-time, and contexts change state infrequently. This approach avoids creating objects that won&apos;t be used, which is important if the State objects store a lot of information. The second approach is better when state changes occur rapidly, in which case you want to avoid destroying states, because they may be needed again shortly. Instantiation costs are paid once up-front, and there are no destruction costs at all. This approach might be inconvenient, though, because the Context must keep references to all states that might be entered.