Direct code:
ackage mainimport "FMT"//now has classrooms and dormitories, classrooms two fans, Windows two meters high, dormitory a door, windows tall rice type room struct { doorNum int windowheight int }func (R *room) showroominfo () { fmt. Println ("Door num:", r.doornum, "Door windowheight:", r.windowheight)}type Roombuilder interface { build () *room}func buildroom (builder Roombuilder) *room { return builder.build ()}type ClassRoomBuilder struct {}func (*classroombuilder) build () *room { return &Room{2, 2}}type DormitoryBuilder struct {}func (*dormitorybuilder) Build () *room { return &room{1, 1}}func main () { room := Buildroom (&classroombuilder{}) room.showroominfo () room = buildroom (&dormitorybuilder{}) room.showroominfo () //the same thing we need a living room a door without windows, you can write a living room builder //The example here is simple, while the actual build function can handle complex things, The builder mode allows you to separate specific //instances from the creation process, so that you can easily extend and replace the creation process}
Go Builder mode, create classrooms and dormitories