This [[Java (programming language)|Java]] example is similar to one in the book ''[[Design Patterns]].''
The MazeGame uses Rooms but it puts the responsibility of creating Rooms to its subclasses which create the concrete classes. The regular game mode could use this template method: