Builder Design Pattern - No Abstract Class / Interface

I wonder if I can implement the Builder design pattern, but without the interface / abstract class from which I get specific collectors? Can I just create one builder?

If I have only a specific builder and director, is it still a builder design template?

More specific:

I have some object that I want to “compose” into a complex object. More precisely, I have the following classes:

Door Wall Room

I want to build a “World” from this class, that is, all these classes together give me peace.

thank

+5
source share
3 answers

, WorldBuilder - , , . , , World .

, :

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();

- - , :

Door door = new Door(roomOne, roomTwo);

, , , , , .

, , , , :

Door door = new Door(roomOneId, roomTwoId);

, 2 , .

Builder , World, , , World .

+3

: - , accept(Visitor v) , node accept.

+2

, - ?

. "", , -, . , , , .

, , , . , .

It’s much easier for me to extract a reasonable interface from the working class, and then try to guess what kind of interface it is and try to develop an interface and a class at the same time.

+2
source

All Articles