forked from go/golangs_learn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
581 B
41 lines
581 B
package builder
|
|
|
|
type Builder interface {
|
|
Build()
|
|
}
|
|
|
|
func NewDirector(b Builder) Director {
|
|
return Director{build: b}
|
|
}
|
|
|
|
type Director struct {
|
|
build Builder
|
|
}
|
|
|
|
func (d *Director) Construct() {
|
|
d.build.Build()
|
|
}
|
|
|
|
type ConcreateBuilder struct {
|
|
Built bool
|
|
}
|
|
|
|
func NewConcreateBuilder() ConcreateBuilder {
|
|
return ConcreateBuilder{Built: false}
|
|
}
|
|
|
|
func (b *ConcreateBuilder) Build() {
|
|
b.Built = true
|
|
}
|
|
|
|
type Product struct {
|
|
Built bool
|
|
}
|
|
|
|
func NewProduct() Product {
|
|
return Product{Built: false}
|
|
}
|
|
|
|
func (b *ConcreateBuilder) GetResult() Product {
|
|
return Product{b.Built}
|
|
}
|
|
|