The State Pattern, or State Machine

preview_player
Показать описание
Applications are stateful, and the objects which run them should be too. Using this pattern will eliminate endless lists of if ... else and swtich ... case statements, putting responsibility back where it belongs - into individual, manageable objects.

We issue the challenge to write a four-operator calculator with no "if" statements.

Note: in the video I incorrectly refer to the "Gang of Five" book. It's actually the "Gang of Four". Oops. It's still a great book to have on your desk.
Рекомендации по теме
Комментарии
Автор

2:05 how the solution, state pattern, came out
2:13 problem
9:34 reuse violation
10:17 example - all-round TV remote control
14:53 how to program the state machine
16:41 state
17:06 state interface - expected to have all of the options in the mentioned controller
17:25 different states - implementation of state

ruixue
Автор

could you WRITE any smaller? (My Best Chandler Bing!)

brookestephen
Автор

Awesome video, super entertaining and extremely informative. you saved my in C# Thanks Gents. !!

daverdal
Автор

That's such a confusing example... If you just used the TV with states as On, Off, Channel1, Channel2 it would be a lot more self explanatory.

elvedrano
Автор

Gang of Five? NO NO NO!!!
IT's THE GANG OF FOUR!!!!

driversteve
Автор

Love you work guys! :) Small tip, though : "Do rehearsals". I mean, for you it may be fun and exciting to just to come-up with examples and explanations on-the-fly, fut for you users, it can become pretty disorienting trying to follow you, while you are changing your minds about what example to use or how to explain something, while in the middle of an explanation - especially if it's like 5 or 6 times in 15 seconds... It makes i very difficult to watch and follow along, so instead of using your viewers as your guinea pigs, a simple solution to that is "rehearsals" - make the refinements "off-camera". Just my 2 cents :)

AinurEru
Автор

Youtube app screws up the order of these vids. No way in the app to order these by date uploaded or anything. Any chance you could order them into a named youtube Playlist? Please and thanks and great vids guys really, great work :) ken

kenCode
Автор

What's the name of the book you are using ?

justgoavocado
Автор

If a LED was connected in that way to the "Brain of Remote Controller" it would never conduct, but anyway it's used here as a symbole :D

DraoN
Автор

You shouldn't smoke weed until after the tutorial...

treyambrose
Автор

Plz concentrate more on explaining than confusing

ErShikharChauhan
Автор

You guys really should have rehearsed this! You've made yourselves look like idiots and so people will give you less respect for what you say you know!

driversteve