Is there a name for this use of the State design pattern?

Posted by Chris C on Programmers See other posts from Programmers or by Chris C
Published on 2012-08-29T17:37:22Z Indexed on 2012/08/29 21:50 UTC
Read the original article Hit count: 246

Filed under:
|

I'm looking to see if there is a particular name for this style of programming a certain kind of behavior into a program.

Said program runs in real time, in an update loop, and the program uses the State design pattern to do some work, but it's the specific way it does the work that I want to know about.

Here's how it's used.

- Object Foo constructed, with concrete StateA object in it
- First loop runs
--- Foo.Run function calls StateA.Bar
--- in StateA.Bar replace Foo's state to StateB
- Second loop runs
--- Foo.Run calls StateB.Bar
- Third loop runs
--- Foo.Run calls StateB.Bar
- Fourth loop
--- etc. 

So in short, Foo doesn't have an explicit Initialize function. It will just have Run, but Run will do something unique in the first frame to initialize something for Foo and then replace it with a different action that will repeat in all the frames following it- thus not needing to check if Foo's already initialized. It's just a "press start and go" action.

What would you call implementing this type of behavior?

© Programmers or respective owner

Related posts about design-patterns

Related posts about real-time