SlideShare a Scribd company logo
1 of 10
State: The Rogue State
(Anti)Pattern
Things going badly when a stateful class takes up arms against its creator
Implement a counter
1. Count to a specified maximum value, then stop.
2. Do not start counting until an initialized signal is received.
3. If a reset signal is received, go back to uninitialized.
4. If a clear signal is received, set the count back to 0, but only if
counting is not in progress.
5. The maximum value can be changed, as long as the counter is not
already counting.
Heading off to the code now…
Advantages of Enum/GoF pattern
They explicitly express important concerns in a clear way.
Advantages of the GoF Pattern
Only variables/constants relevant to a state are available
in that state
Advantages of the GoF Pattern
Easier to reason about, because determining what state
the system is in, has been separated from what to do in
response to various signals/messages.
Specifically, class structure has replaced conditional logic.
(Single Responsibility Principle)
Advantages of the GoF Pattern
Changes largely result in adding classes/methods, as
opposed to editing existing methods.
Open [for extension]/Closed [for modification] Principle
Advantages of the GoF Pattern
Code is about communication with other developers (as a
fringe benefit users get to do stuff).
The state pattern is easier to understand.
Addendum to last week:
Program Architecture and SRP
Data Object
(the business
domain data)
Business Methods
(only operate on data
objects, NO dependency
injection)
Composing Dependencies
(Manager/Handler/BL
layer)

More Related Content

Viewers also liked

Efraín Jesús Rojas Mata: 3 pistas de aterrizaje seguras aunque no lo parezcan
Efraín Jesús Rojas Mata: 3 pistas de aterrizaje seguras aunque no lo parezcanEfraín Jesús Rojas Mata: 3 pistas de aterrizaje seguras aunque no lo parezcan
Efraín Jesús Rojas Mata: 3 pistas de aterrizaje seguras aunque no lo parezcanEfrain Jesus Rojas Mata
 
Presentation1
Presentation1Presentation1
Presentation1moneyboy3
 
Fisiologia - Sistema Renal
Fisiologia - Sistema RenalFisiologia - Sistema Renal
Fisiologia - Sistema RenalPedro Miguel
 
दिल में छुपा है रोबोट
दिल में छुपा है रोबोटदिल में छुपा है रोबोट
दिल में छुपा है रोबोटANSHU KHANDELWAL
 
Bases contrato cas 2017 programa 090
Bases contrato cas 2017 programa 090Bases contrato cas 2017 programa 090
Bases contrato cas 2017 programa 090Jesus Franco
 

Viewers also liked (10)

Efraín Jesús Rojas Mata: 3 pistas de aterrizaje seguras aunque no lo parezcan
Efraín Jesús Rojas Mata: 3 pistas de aterrizaje seguras aunque no lo parezcanEfraín Jesús Rojas Mata: 3 pistas de aterrizaje seguras aunque no lo parezcan
Efraín Jesús Rojas Mata: 3 pistas de aterrizaje seguras aunque no lo parezcan
 
Practica quimica
Practica quimica Practica quimica
Practica quimica
 
Presentation1
Presentation1Presentation1
Presentation1
 
Fisiologia - Sistema Renal
Fisiologia - Sistema RenalFisiologia - Sistema Renal
Fisiologia - Sistema Renal
 
Características generales de los seres vivos
Características generales de los seres vivosCaracterísticas generales de los seres vivos
Características generales de los seres vivos
 
दिल में छुपा है रोबोट
दिल में छुपा है रोबोटदिल में छुपा है रोबोट
दिल में छुपा है रोबोट
 
Thyroid slideshare
Thyroid slideshareThyroid slideshare
Thyroid slideshare
 
Bases contrato cas 2017 programa 090
Bases contrato cas 2017 programa 090Bases contrato cas 2017 programa 090
Bases contrato cas 2017 programa 090
 
La misa del domingo 12 de marzo
La misa del domingo 12 de marzoLa misa del domingo 12 de marzo
La misa del domingo 12 de marzo
 
Hojita de los niños
Hojita de los niñosHojita de los niños
Hojita de los niños
 

Recently uploaded

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Recently uploaded (20)

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 

Gang-Of-Four State Pattern

  • 1. State: The Rogue State (Anti)Pattern Things going badly when a stateful class takes up arms against its creator
  • 2. Implement a counter 1. Count to a specified maximum value, then stop. 2. Do not start counting until an initialized signal is received. 3. If a reset signal is received, go back to uninitialized. 4. If a clear signal is received, set the count back to 0, but only if counting is not in progress. 5. The maximum value can be changed, as long as the counter is not already counting.
  • 3. Heading off to the code now…
  • 4.
  • 5. Advantages of Enum/GoF pattern They explicitly express important concerns in a clear way.
  • 6. Advantages of the GoF Pattern Only variables/constants relevant to a state are available in that state
  • 7. Advantages of the GoF Pattern Easier to reason about, because determining what state the system is in, has been separated from what to do in response to various signals/messages. Specifically, class structure has replaced conditional logic. (Single Responsibility Principle)
  • 8. Advantages of the GoF Pattern Changes largely result in adding classes/methods, as opposed to editing existing methods. Open [for extension]/Closed [for modification] Principle
  • 9. Advantages of the GoF Pattern Code is about communication with other developers (as a fringe benefit users get to do stuff). The state pattern is easier to understand.
  • 10. Addendum to last week: Program Architecture and SRP Data Object (the business domain data) Business Methods (only operate on data objects, NO dependency injection) Composing Dependencies (Manager/Handler/BL layer)