Yes, absolutely you can have a simple WorldBuilder whos job is to create a fully configured world comprised of Doors, Walls, and Rooms. This is a very useful when you don't want to have a partially built, and possibly invalid, World object exposed.
Let's say the usage of the builder is like this:
WorldBuilder builder = new WorldBuilder(); // read the definition of a room from an XML file or other source. // this is vastily simplified, you'd probably be iteration // something like this: // // for each Room in file // for each wall in room // for each door in wall // roomId = readRoomId(); wallId = readWallId(); doorId = readDoorId(); destRoomId = readDestinationRoomId(); builder.AddRoom(roomId); builder.AddWallToRoom(roomId, wallId, SIDE.NORTH); builder.AddDoorToWall(wallId, DOORSTYLE.WOODEN | DOORSTYLE.LOCKED, destRoomId); // etc, etc World world = builder.makeWorld();
A non-builder approach might want to do something like this to connect two rooms objects:
Door door = new Door(roomOne, roomTwo);
But if you were iterating each room from a file as before then you won't have a reference to the second room because it may not have even been reached yet.
An alternative approach is to give each object just the ID of its neighbors or parent so you get this instead, which allows you to refer to an object that has not been loaded yet:
Door door = new Door(roomOneId, roomTwoId);
But if there was an error in the file and room 2 was never defined then the World would be invalid.
The Builder can take care of all of the details of properly constructing, connecting, and validating the World creation process, granting flexibility to client code that wants to create the world, and releaving the World object of complex construction logic.