Reader small image

You're reading from  Game Development Patterns with Unity 2021 - Second Edition

Product typeBook
Published inJul 2021
Reading LevelBeginner
PublisherPackt
ISBN-139781800200814
Edition2nd Edition
Languages
Tools
Right arrow
Author (1)
David Baron
David Baron
author image
David Baron

David Baron is a game developer with over 15 years of experience in the industry. He has worked for some well-known AAA, mobile, and indie game studios in Montreal, Canada. His skill set includes programming, design, and 3D art. As a programmer, he has worked on various games for various platforms, including virtual reality, mobile, and consoles.
Read more about David Baron

Right arrow

An overview of the State pattern

We use the State design pattern to implement a system that will permit an object to change its behavior based on its internal state. Thus, a change of context will bring on a change of behavior.

The State pattern has three core participants in its structure:

  • The Context class defines an interface that permits a client to request a change in the internal state of an object. It also holds a pointer to the current state.
  • The IState interface establishes an implementation contract for the concrete state classes.
  • The ConcreteState classes implement the IState interface and expose a public method named handle() that the Context object can call to trigger the state's behavior.

Let's now review a diagram of this pattern definition, but in the context of an actual implementation:

Figure 5.1 – UML diagram of the State pattern

To update an object's state, the client can set the expected state through the Context...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Game Development Patterns with Unity 2021 - Second Edition
Published in: Jul 2021Publisher: PacktISBN-13: 9781800200814

Author (1)

author image
David Baron

David Baron is a game developer with over 15 years of experience in the industry. He has worked for some well-known AAA, mobile, and indie game studios in Montreal, Canada. His skill set includes programming, design, and 3D art. As a programmer, he has worked on various games for various platforms, including virtual reality, mobile, and consoles.
Read more about David Baron