state machine presentation1 61
TRANSCRIPT
![Page 1: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/1.jpg)
The State Pattern
Thursday, March 18, 2010
![Page 2: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/2.jpg)
The State PatternAn Appalling Exploration
Thursday, March 18, 2010
![Page 3: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/3.jpg)
?
Thursday, March 18, 2010
![Page 4: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/4.jpg)
?
Thursday, March 18, 2010
![Page 5: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/5.jpg)
Thursday, March 18, 2010
![Page 6: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/6.jpg)
Thursday, March 18, 2010
![Page 7: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/7.jpg)
Thursday, March 18, 2010
![Page 8: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/8.jpg)
Thursday, March 18, 2010
![Page 9: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/9.jpg)
Thursday, March 18, 2010
![Page 10: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/10.jpg)
Thursday, March 18, 2010
![Page 11: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/11.jpg)
Thursday, March 18, 2010
![Page 12: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/12.jpg)
Thursday, March 18, 2010
![Page 13: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/13.jpg)
Thursday, March 18, 2010
![Page 14: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/14.jpg)
Thursday, March 18, 2010
![Page 15: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/15.jpg)
Thursday, March 18, 2010
![Page 16: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/16.jpg)
Thursday, March 18, 2010
![Page 17: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/17.jpg)
:)
Thursday, March 18, 2010
![Page 18: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/18.jpg)
Why we need it...
Thursday, March 18, 2010
![Page 19: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/19.jpg)
B. F. Skinner(do not do what he did)
Thursday, March 18, 2010
![Page 20: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/20.jpg)
Thursday, March 18, 2010
![Page 21: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/21.jpg)
Skinner box“Operant
Conditioning Chamber”
Thursday, March 18, 2010
![Page 22: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/22.jpg)
Thursday, March 18, 2010
![Page 23: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/23.jpg)
FAIL
Thursday, March 18, 2010
![Page 24: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/24.jpg)
What you do depends on your state
Thursday, March 18, 2010
![Page 25: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/25.jpg)
Blood test
Thursday, March 18, 2010
![Page 26: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/26.jpg)
Thursday, March 18, 2010
![Page 27: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/27.jpg)
Blood test
NotThing
Thursday, March 18, 2010
![Page 28: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/28.jpg)
Thursday, March 18, 2010
![Page 29: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/29.jpg)
Blood test
NotThing
Thing
Thursday, March 18, 2010
![Page 30: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/30.jpg)
Thursday, March 18, 2010
![Page 31: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/31.jpg)
Firstaid
Thursday, March 18, 2010
![Page 32: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/32.jpg)
Firstaid
NotThing
Thursday, March 18, 2010
![Page 33: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/33.jpg)
Thursday, March 18, 2010
![Page 34: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/34.jpg)
Firstaid
NotThing
Thing
Thursday, March 18, 2010
![Page 35: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/35.jpg)
Thursday, March 18, 2010
![Page 36: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/36.jpg)
Firstaid
NotThing
Thing
Blood test
NotThing
Thing
Thursday, March 18, 2010
![Page 37: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/37.jpg)
Firstaid
NotThing
Thing
Blood test
NotThing
Thing
Thursday, March 18, 2010
![Page 38: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/38.jpg)
1. Repeatedly using same test
2. Answers to test are predictable and repeated
3. Test concerns one’s own internal matters
Thursday, March 18, 2010
![Page 39: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/39.jpg)
Time to get practical.
Thursday, March 18, 2010
![Page 40: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/40.jpg)
Thursday, March 18, 2010
![Page 41: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/41.jpg)
public class Creature{ public function Creature() { trace(“Ecce Creature”); }}
Thursday, March 18, 2010
![Page 42: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/42.jpg)
Thursday, March 18, 2010
![Page 43: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/43.jpg)
1. Come to life
Thursday, March 18, 2010
![Page 44: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/44.jpg)
1. Come to life2. Talk to us
Thursday, March 18, 2010
![Page 45: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/45.jpg)
1. Come to life2. Talk to us3. Move around
Thursday, March 18, 2010
![Page 46: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/46.jpg)
public class Creature{
public function Creature() { trace(“Ecce Creature”); }
public function zap() {}
public function talk() {}
public function walk() {} }
Thursday, March 18, 2010
![Page 47: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/47.jpg)
public class Creature{
public function Creature() { trace(“Ecce Creature”); }
public function zap() {}
public function talk() {}
public function walk() {} }
Thursday, March 18, 2010
![Page 48: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/48.jpg)
Thursday, March 18, 2010
![Page 49: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/49.jpg)
Thursday, March 18, 2010
![Page 50: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/50.jpg)
Thursday, March 18, 2010
![Page 51: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/51.jpg)
... public function implant( b : Brain ) { mybrain = b; }...
Thursday, March 18, 2010
![Page 52: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/52.jpg)
Thursday, March 18, 2010
![Page 53: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/53.jpg)
public function zap() { // IF DEAD, BECOME ALIVE // IF ALIVE, BECOME DEAD
}
public function walk() {
}
public function talk() { }
Thursday, March 18, 2010
![Page 54: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/54.jpg)
public function zap() { // IF DEAD, BECOME ALIVE // IF ALIVE, BECOME DEAD
}
public function talk() { // IF DEAD, DO NOTHING // IF ALIVE, DESCRIBE CANCER CURE
} public function walk() {
}
Thursday, March 18, 2010
![Page 55: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/55.jpg)
public function zap() { // IF DEAD, BECOME ALIVE // IF ALIVE, BECOME DEAD
}
public function talk() { // IF DEAD, DO NOTHING // IF ALIVE, DESCRIBE CANCER CURE
}
public function walk() { // IF DEAD, DO NOTHING // IF ALIVE, WALK TO LAB
}
Thursday, March 18, 2010
![Page 56: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/56.jpg)
x_x
Thursday, March 18, 2010
![Page 57: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/57.jpg)
o_o
Thursday, March 18, 2010
![Page 58: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/58.jpg)
0.0
Thursday, March 18, 2010
![Page 59: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/59.jpg)
x_x
Thursday, March 18, 2010
![Page 60: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/60.jpg)
?
Thursday, March 18, 2010
![Page 61: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/61.jpg)
Thursday, March 18, 2010
![Page 62: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/62.jpg)
public class Creature{ private var amIdead : Boolean;
public function Creature() { trace(“Ecce Creature”); amIdead = true;
}
public function zap() { if( amIdead ) { amIdead = false;
} else
{ amIdead = false;
}}
public function talk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ trace(“Listen to this...”); trace(“the secrets of eternity”);
}}
public function walk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ trace(“I’ll go to my lab”); trace(“and cure cancer”);
}}
}
Thursday, March 18, 2010
![Page 63: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/63.jpg)
public class Creature{ private var amIdead : Boolean;
public function Creature() { trace(“Ecce Creature”); amIdead = true;
}
public function zap() { if( amIdead ) { amIdead = false;
} else
{ amIdead = false;
}}
public function talk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ trace(“Listen to this...”); trace(“the secrets of eternity”);
}}
public function walk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ trace(“I’ll go to my lab”); trace(“and cure cancer”);
}}
}
Thursday, March 18, 2010
![Page 64: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/64.jpg)
public class Creature{ private var amIdead : Boolean;
public function Creature() { trace(“Ecce Creature”); amIdead = true;
}
public function zap() { if( amIdead ) { amIdead = false;
} else
{ amIdead = false;
}}
public function talk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ trace(“Listen to this...”); trace(“the secrets of eternity”);
}}
public function walk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ trace(“I’ll go to my lab”); trace(“and cure cancer”);
}}
}
Thursday, March 18, 2010
![Page 65: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/65.jpg)
public class Creature{ private var amIdead : Boolean;
public function Creature() { trace(“Ecce Creature”); amIdead = true;
}
public function zap() { if( amIdead ) { amIdead = false;
} else
{ amIdead = false;
}}
public function talk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ trace(“Listen to this...”); trace(“the secrets of eternity”);
}}
public function walk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ trace(“I’ll go to my lab”); trace(“and cure cancer”);
}}
}Thursday, March 18, 2010
![Page 66: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/66.jpg)
[clip: Igor drops Hans Delbruck’s brain]
Thursday, March 18, 2010
![Page 67: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/67.jpg)
Thursday, March 18, 2010
![Page 68: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/68.jpg)
public class Creature{ private var amIdead : Boolean; private var doIHaveDelbruckBrain : Boolean;
public function Creature() { trace(“Ecce Creature”); amIdead = true;
}
public function implant( b : Brain ) { mybrain = b; if( mybrain == DELBRUCK_BRAIN ) // how?? { doIHaveDelbruckBrain = true; } else { doIHaveDelbruckBrain = false; } }
public function zap() { if( amIdead ) { amIdead = false;
} else
{ amIdead = false;
}}
public function talk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ if( doIHaveDelbruckBrain ) {
trace(“Listen to this...”); trace(“the secrets of eternity”); } else { trace(“UNNNNNNNH”); }
}
Thursday, March 18, 2010
![Page 69: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/69.jpg)
public class Creature{ private var amIdead : Boolean; private var doIHaveDelbruckBrain : Boolean;
public function Creature() { trace(“Ecce Creature”); amIdead = true;
}
public function implant( b : Brain ) { mybrain = b; if( mybrain == DELBRUCK_BRAIN ) // how?? { doIHaveDelbruckBrain = true; } else { doIHaveDelbruckBrain = false; } }
public function zap() { if( amIdead ) { amIdead = false;
} else
{ amIdead = false;
}}
public function talk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ if( doIHaveDelbruckBrain ) {
trace(“Listen to this...”); trace(“the secrets of eternity”); } else { trace(“UNNNNNNNH”); }
}
Thursday, March 18, 2010
![Page 70: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/70.jpg)
public class Creature{ private var amIdead : Boolean; private var doIHaveDelbruckBrain : Boolean;
public function Creature() { trace(“Ecce Creature”); amIdead = true;
}
public function implant( b : Brain ) { mybrain = b; if( mybrain == DELBRUCK_BRAIN ) // how?? { doIHaveDelbruckBrain = true; } else { doIHaveDelbruckBrain = false; } }
public function zap() { if( amIdead ) { amIdead = false;
} else
{ amIdead = false;
}}
public function talk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ if( doIHaveDelbruckBrain ) {
trace(“Listen to this...”); trace(“the secrets of eternity”); } else { trace(“UNNNNNNNH”); }
}
Thursday, March 18, 2010
![Page 71: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/71.jpg)
public class Creature{ private var amIdead : Boolean; private var doIHaveDelbruckBrain : Boolean;
public function Creature() { trace(“Ecce Creature”); amIdead = true;
}
public function implant( b : Brain ) { mybrain = b; if( mybrain == DELBRUCK_BRAIN ) // how?? { doIHaveDelbruckBrain = true; } else { doIHaveDelbruckBrain = false; } }
public function zap() { if( amIdead ) { amIdead = false;
} else
{ amIdead = false;
}}
public function talk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ if( doIHaveDelbruckBrain ) {
trace(“Listen to this...”); trace(“the secrets of eternity”); } else { trace(“UNNNNNNNH”); }
}
Thursday, March 18, 2010
![Page 72: State Machine Presentation1 61](https://reader034.vdocuments.site/reader034/viewer/2022052622/5592c0dd1a28abe9408b47a5/html5/thumbnails/72.jpg)
public class Creature{ private var amIdead : Boolean; private var doIHaveDelbruckBrain : Boolean;
public function Creature() { trace(“Ecce Creature”); amIdead = true;
}
public function implant( b : Brain ) { mybrain = b; if( mybrain == DELBRUCK_BRAIN ) // how?? { doIHaveDelbruckBrain = true; } else { doIHaveDelbruckBrain = false; } }
public function zap() { if( amIdead ) { amIdead = false;
} else
{ amIdead = false;
}}
public function talk() { if( amIdead ) { // DO NOTHING -- I’M DEAD
} else
{ if( doIHaveDelbruckBrain ) {
trace(“Listen to this...”); trace(“the secrets of eternity”); } else { trace(“UNNNNNNNH”); }
}
Thursday, March 18, 2010