SlideShare a Scribd company logo

State Pattern In Flex

T
T

A tutorial on how to implement the State design pattern in Flex 3. We are going to have a traffic light move through several states (red, orange, green). Of course there are other states the traffic light might be in, as well as transitional states (green and orange at the same time), but lets keep things simple!

State Pattern In Flex

1 of 16
Download to read offline
Andy Bulka
Technical Director
Austhink Software
www.austhink.com
State
 Alter an object's behavior when its state changes. Put
the “state” in a class and delegate to it.
Intent
 Allow an object to alter its behavior when its internal
state changes. The object will appear to change its
class.
State pattern - UML
 Client code talks to the “context.Request()” which
behaves differently
 So what if
you want
to add the
new
"Orange"
state?
You
usually
have to
modify
code in a
number
of places.
State Pattern In Flex
State instances as Singletons
 You often want to have singleton states rather than
recreating each state time and time again, and having
to copy across any state attributes each time. Of
course by keeping most of the attributes in the
context, there is not much data in state to copy
between state instance when the state switches.

Recommended

Evolution of front end architectures
Evolution of front end architecturesEvolution of front end architectures
Evolution of front end architecturesluca mezzalira
 
Reactive programming with cycle.js
Reactive programming with cycle.jsReactive programming with cycle.js
Reactive programming with cycle.jsluca mezzalira
 
Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design PatternsLidan Hifi
 
Unit 3(advanced state modeling & interaction meodelling)
Unit  3(advanced state modeling & interaction meodelling)Unit  3(advanced state modeling & interaction meodelling)
Unit 3(advanced state modeling & interaction meodelling)Manoj Reddy
 
5.state diagrams
5.state diagrams5.state diagrams
5.state diagramsAPU
 
Pertemuan 6-2-sequence-diagram
Pertemuan 6-2-sequence-diagramPertemuan 6-2-sequence-diagram
Pertemuan 6-2-sequence-diagramAbi Bobon
 

More Related Content

Similar to State Pattern In Flex

Memento Pattern Implementation
Memento Pattern ImplementationMemento Pattern Implementation
Memento Pattern ImplementationSteve Widom
 
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq PermanaJetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq PermanaDicodingEvent
 
Design Patterns
Design PatternsDesign Patterns
Design Patternssoms_1
 
M03 2 Behavioral Diagrams
M03 2 Behavioral DiagramsM03 2 Behavioral Diagrams
M03 2 Behavioral DiagramsDang Tuan
 
Unity3D Scripting: State Machine
Unity3D Scripting: State MachineUnity3D Scripting: State Machine
Unity3D Scripting: State MachineSperasoft
 
CS8592 Object Oriented Analysis & Design - UNIT III
CS8592 Object Oriented Analysis & Design - UNIT III CS8592 Object Oriented Analysis & Design - UNIT III
CS8592 Object Oriented Analysis & Design - UNIT III pkaviya
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionVisual Engineering
 
Game Programming Pattern by Restya
Game Programming Pattern by RestyaGame Programming Pattern by Restya
Game Programming Pattern by RestyaAgate Studio
 
Sprouting into the world of Elm
Sprouting into the world of ElmSprouting into the world of Elm
Sprouting into the world of ElmMike Onslow
 
WPF Windows Presentation Foundation A detailed overview Version1.2
WPF Windows Presentation Foundation A detailed overview Version1.2WPF Windows Presentation Foundation A detailed overview Version1.2
WPF Windows Presentation Foundation A detailed overview Version1.2Shahzad
 

Similar to State Pattern In Flex (20)

State Pattern in Flex
State Pattern in FlexState Pattern in Flex
State Pattern in Flex
 
Memento Pattern Implementation
Memento Pattern ImplementationMemento Pattern Implementation
Memento Pattern Implementation
 
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq PermanaJetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
M03 2 Behavioral Diagrams
M03 2 Behavioral DiagramsM03 2 Behavioral Diagrams
M03 2 Behavioral Diagrams
 
Uml and enterprise architect
Uml and enterprise architectUml and enterprise architect
Uml and enterprise architect
 
Unity3D Scripting: State Machine
Unity3D Scripting: State MachineUnity3D Scripting: State Machine
Unity3D Scripting: State Machine
 
CS8592 Object Oriented Analysis & Design - UNIT III
CS8592 Object Oriented Analysis & Design - UNIT III CS8592 Object Oriented Analysis & Design - UNIT III
CS8592 Object Oriented Analysis & Design - UNIT III
 
Intro Uml
Intro UmlIntro Uml
Intro Uml
 
Lift Framework
Lift FrameworkLift Framework
Lift Framework
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS Introduction
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Visitor design patterns
Visitor design patternsVisitor design patterns
Visitor design patterns
 
Game Programming Pattern by Restya
Game Programming Pattern by RestyaGame Programming Pattern by Restya
Game Programming Pattern by Restya
 
State patterns
State patternsState patterns
State patterns
 
CS8592-OOAD Lecture Notes Unit-3
CS8592-OOAD Lecture Notes Unit-3CS8592-OOAD Lecture Notes Unit-3
CS8592-OOAD Lecture Notes Unit-3
 
Sprouting into the world of Elm
Sprouting into the world of ElmSprouting into the world of Elm
Sprouting into the world of Elm
 
WPF Windows Presentation Foundation A detailed overview Version1.2
WPF Windows Presentation Foundation A detailed overview Version1.2WPF Windows Presentation Foundation A detailed overview Version1.2
WPF Windows Presentation Foundation A detailed overview Version1.2
 
Uml Diagrams
Uml DiagramsUml Diagrams
Uml Diagrams
 

More from tcab22

Null Object Design Pattern
Null Object Design PatternNull Object Design Pattern
Null Object Design Patterntcab22
 
Blackboard Pattern
Blackboard PatternBlackboard Pattern
Blackboard Patterntcab22
 
Tooled Composite Design Pattern
Tooled Composite Design PatternTooled Composite Design Pattern
Tooled Composite Design Patterntcab22
 
Tooled Composite Design Pattern presentation
Tooled Composite Design Pattern presentationTooled Composite Design Pattern presentation
Tooled Composite Design Pattern presentationtcab22
 
Andy Bulka Pattern Automation
Andy Bulka Pattern AutomationAndy Bulka Pattern Automation
Andy Bulka Pattern Automationtcab22
 
Representing Design Patterns In Uml Andy Bulka Oct2006
Representing Design Patterns In Uml Andy Bulka Oct2006Representing Design Patterns In Uml Andy Bulka Oct2006
Representing Design Patterns In Uml Andy Bulka Oct2006tcab22
 

More from tcab22 (6)

Null Object Design Pattern
Null Object Design PatternNull Object Design Pattern
Null Object Design Pattern
 
Blackboard Pattern
Blackboard PatternBlackboard Pattern
Blackboard Pattern
 
Tooled Composite Design Pattern
Tooled Composite Design PatternTooled Composite Design Pattern
Tooled Composite Design Pattern
 
Tooled Composite Design Pattern presentation
Tooled Composite Design Pattern presentationTooled Composite Design Pattern presentation
Tooled Composite Design Pattern presentation
 
Andy Bulka Pattern Automation
Andy Bulka Pattern AutomationAndy Bulka Pattern Automation
Andy Bulka Pattern Automation
 
Representing Design Patterns In Uml Andy Bulka Oct2006
Representing Design Patterns In Uml Andy Bulka Oct2006Representing Design Patterns In Uml Andy Bulka Oct2006
Representing Design Patterns In Uml Andy Bulka Oct2006
 

Recently uploaded

Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)
Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)
Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)GDSCNiT
 
Self scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloadsSelf scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloadsBram Vogelaar
 
AUTOKEYUNLOCKER-BRANDS-SUPPORT-STANDARD-VERSION.pdf
AUTOKEYUNLOCKER-BRANDS-SUPPORT-STANDARD-VERSION.pdfAUTOKEYUNLOCKER-BRANDS-SUPPORT-STANDARD-VERSION.pdf
AUTOKEYUNLOCKER-BRANDS-SUPPORT-STANDARD-VERSION.pdfAutokey
 
unit I lecture 5 - Software Development Life Cycle.pdf
unit I lecture 5 - Software Development Life Cycle.pdfunit I lecture 5 - Software Development Life Cycle.pdf
unit I lecture 5 - Software Development Life Cycle.pdfStephenTec
 
unit I lecture 4 - AGILE DEVELOPMENT AND PLAN-DRIVEN.pdf
unit I lecture 4 - AGILE DEVELOPMENT AND PLAN-DRIVEN.pdfunit I lecture 4 - AGILE DEVELOPMENT AND PLAN-DRIVEN.pdf
unit I lecture 4 - AGILE DEVELOPMENT AND PLAN-DRIVEN.pdfStephenTec
 
Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...
Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...
Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...confluent
 
Essence of Requirements Engineering: Pragmatic Insights for 2024
Essence of Requirements Engineering: Pragmatic Insights for 2024Essence of Requirements Engineering: Pragmatic Insights for 2024
Essence of Requirements Engineering: Pragmatic Insights for 2024Asher Sterkin
 
unit I lecture 3 - Software Process Models.pdf
unit I lecture 3 - Software Process Models.pdfunit I lecture 3 - Software Process Models.pdf
unit I lecture 3 - Software Process Models.pdfStephenTec
 
Sql server types of joins with example.pptx
Sql server types of joins with example.pptxSql server types of joins with example.pptx
Sql server types of joins with example.pptxsameer gaikwad
 
Enabling Enterprise-wide OT Data access with Matrikon Data Broker.pdf
Enabling Enterprise-wide OT Data access  with Matrikon Data Broker.pdfEnabling Enterprise-wide OT Data access  with Matrikon Data Broker.pdf
Enabling Enterprise-wide OT Data access with Matrikon Data Broker.pdfJohn Archer
 
100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS
100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS
100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTSi-engage
 
Steps to Build a PWA with Odoo.pdf
Steps to Build a PWA with Odoo.pdfSteps to Build a PWA with Odoo.pdf
Steps to Build a PWA with Odoo.pdfayushinwizards
 
unit I lecture 2 - Software Engineering Ethics - Software Process.pdf
unit I lecture 2 - Software Engineering Ethics - Software Process.pdfunit I lecture 2 - Software Engineering Ethics - Software Process.pdf
unit I lecture 2 - Software Engineering Ethics - Software Process.pdfStephenTec
 
Manual de la Mezcladora SoundCraft Notepad -12Fx
Manual de la Mezcladora SoundCraft Notepad -12FxManual de la Mezcladora SoundCraft Notepad -12Fx
Manual de la Mezcladora SoundCraft Notepad -12Fxjavierdavidvelasco17
 
App Builder - Hierarchical Data Apps.pptx
App Builder - Hierarchical Data Apps.pptxApp Builder - Hierarchical Data Apps.pptx
App Builder - Hierarchical Data Apps.pptxPoojitha B
 
Embracing Change - The Impact of Generative AI on Strategic Portfolio Management
Embracing Change - The Impact of Generative AI on Strategic Portfolio ManagementEmbracing Change - The Impact of Generative AI on Strategic Portfolio Management
Embracing Change - The Impact of Generative AI on Strategic Portfolio ManagementOnePlan Solutions
 
India's_Generative_AI_Startup_Landscape_Report_2023_Inc42 (1).pdf
India's_Generative_AI_Startup_Landscape_Report_2023_Inc42 (1).pdfIndia's_Generative_AI_Startup_Landscape_Report_2023_Inc42 (1).pdf
India's_Generative_AI_Startup_Landscape_Report_2023_Inc42 (1).pdfgranitesrijan
 
maximum subarray ppt for killing camp students
maximum subarray ppt for killing camp studentsmaximum subarray ppt for killing camp students
maximum subarray ppt for killing camp studentsssuser82c38d
 
Getting Started with Trello for Beginners.pptx
Getting Started with Trello for Beginners.pptxGetting Started with Trello for Beginners.pptx
Getting Started with Trello for Beginners.pptxmavinoikein
 

Recently uploaded (20)

Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)
Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)
Open Sprintera (Where Open Source Sparks a Sprint of Possibilities)
 
Self scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloadsSelf scaling Multi cloud nomad workloads
Self scaling Multi cloud nomad workloads
 
AUTOKEYUNLOCKER-BRANDS-SUPPORT-STANDARD-VERSION.pdf
AUTOKEYUNLOCKER-BRANDS-SUPPORT-STANDARD-VERSION.pdfAUTOKEYUNLOCKER-BRANDS-SUPPORT-STANDARD-VERSION.pdf
AUTOKEYUNLOCKER-BRANDS-SUPPORT-STANDARD-VERSION.pdf
 
unit I lecture 5 - Software Development Life Cycle.pdf
unit I lecture 5 - Software Development Life Cycle.pdfunit I lecture 5 - Software Development Life Cycle.pdf
unit I lecture 5 - Software Development Life Cycle.pdf
 
unit I lecture 4 - AGILE DEVELOPMENT AND PLAN-DRIVEN.pdf
unit I lecture 4 - AGILE DEVELOPMENT AND PLAN-DRIVEN.pdfunit I lecture 4 - AGILE DEVELOPMENT AND PLAN-DRIVEN.pdf
unit I lecture 4 - AGILE DEVELOPMENT AND PLAN-DRIVEN.pdf
 
Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...
Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...
Industry 4.0: Building the Unified Namespace with Confluent, HiveMQ and Spark...
 
Essence of Requirements Engineering: Pragmatic Insights for 2024
Essence of Requirements Engineering: Pragmatic Insights for 2024Essence of Requirements Engineering: Pragmatic Insights for 2024
Essence of Requirements Engineering: Pragmatic Insights for 2024
 
unit I lecture 3 - Software Process Models.pdf
unit I lecture 3 - Software Process Models.pdfunit I lecture 3 - Software Process Models.pdf
unit I lecture 3 - Software Process Models.pdf
 
Sql server types of joins with example.pptx
Sql server types of joins with example.pptxSql server types of joins with example.pptx
Sql server types of joins with example.pptx
 
Enabling Enterprise-wide OT Data access with Matrikon Data Broker.pdf
Enabling Enterprise-wide OT Data access  with Matrikon Data Broker.pdfEnabling Enterprise-wide OT Data access  with Matrikon Data Broker.pdf
Enabling Enterprise-wide OT Data access with Matrikon Data Broker.pdf
 
100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS
100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS
100 TOOLS TO MEASURE AND ANALYSE YOUR DIGITAL MARKETING EFFORTS
 
Steps to Build a PWA with Odoo.pdf
Steps to Build a PWA with Odoo.pdfSteps to Build a PWA with Odoo.pdf
Steps to Build a PWA with Odoo.pdf
 
unit I lecture 2 - Software Engineering Ethics - Software Process.pdf
unit I lecture 2 - Software Engineering Ethics - Software Process.pdfunit I lecture 2 - Software Engineering Ethics - Software Process.pdf
unit I lecture 2 - Software Engineering Ethics - Software Process.pdf
 
Manual de la Mezcladora SoundCraft Notepad -12Fx
Manual de la Mezcladora SoundCraft Notepad -12FxManual de la Mezcladora SoundCraft Notepad -12Fx
Manual de la Mezcladora SoundCraft Notepad -12Fx
 
App Builder - Hierarchical Data Apps.pptx
App Builder - Hierarchical Data Apps.pptxApp Builder - Hierarchical Data Apps.pptx
App Builder - Hierarchical Data Apps.pptx
 
Embracing Change - The Impact of Generative AI on Strategic Portfolio Management
Embracing Change - The Impact of Generative AI on Strategic Portfolio ManagementEmbracing Change - The Impact of Generative AI on Strategic Portfolio Management
Embracing Change - The Impact of Generative AI on Strategic Portfolio Management
 
India's_Generative_AI_Startup_Landscape_Report_2023_Inc42 (1).pdf
India's_Generative_AI_Startup_Landscape_Report_2023_Inc42 (1).pdfIndia's_Generative_AI_Startup_Landscape_Report_2023_Inc42 (1).pdf
India's_Generative_AI_Startup_Landscape_Report_2023_Inc42 (1).pdf
 
Features of IETM Software -Code and Pixels
Features of IETM Software -Code and PixelsFeatures of IETM Software -Code and Pixels
Features of IETM Software -Code and Pixels
 
maximum subarray ppt for killing camp students
maximum subarray ppt for killing camp studentsmaximum subarray ppt for killing camp students
maximum subarray ppt for killing camp students
 
Getting Started with Trello for Beginners.pptx
Getting Started with Trello for Beginners.pptxGetting Started with Trello for Beginners.pptx
Getting Started with Trello for Beginners.pptx
 

State Pattern In Flex

  • 1. Andy Bulka Technical Director Austhink Software www.austhink.com
  • 2. State  Alter an object's behavior when its state changes. Put the “state” in a class and delegate to it. Intent  Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
  • 3. State pattern - UML  Client code talks to the “context.Request()” which behaves differently
  • 4.  So what if you want to add the new "Orange" state? You usually have to modify code in a number of places.
  • 6. State instances as Singletons  You often want to have singleton states rather than recreating each state time and time again, and having to copy across any state attributes each time. Of course by keeping most of the attributes in the context, there is not much data in state to copy between state instance when the state switches.
  • 7. What States instances can access  One main issue in state pattern is how do state instances access attributes in the context. Simplest solution is to have a pointer back from each state object back to the context. Another solution is to completely decouple the state from the context and simply pass the state instance what it needs e.g. as parameters to state methods (as defined in the the state interface)
  • 8. Who changes the state  Sometimes client code drives the changing of the state  Sometimes client code holds the state instances too, though I prefer to map these to enums and look them up in a dictionary (see singleton issue above)  Often the states themselves or the context (e.g. car) will take on this responsibility. If the states are given the power to set the next state – they will need need access to the context (via a backpointer) so that they can call a method called e.g. SetState().
  • 10. Flex 3 classes  Implement dumb graphic in either flash or mxml  Deep state pattern switching logic is in pure actionscript code  Hook up the gui to the pattern using various techniques
  • 11. Flash – dumb graphic  Graphics reified as symbols  Symbols given names  Symbols marked as inheriting from Flex’s mx.flash.UIMovieClip Should actually be com.Traf ficLightC ontroller
  • 12. UML 1  Simple version – flash component subclasses “context”
  • 14. Re the behaviour - display() Three versions of implementing the graphic part is shown.  pure mxml (code embedded inside the mxml)  mxml + actionscript class  flash component (dumb)
  • 15. Flex 3 MXML graphics
  • 16. End. Advert Design Pattern Courses - for your company Elevate the effectiveness of your entire programming team - Andy can deliver a design patterns course to you programming team on your company's premises. Check out the details here. http://www.atug.com/andypatterns/training_courses.htm