diff --git a/creation/06_builder/builder.go b/creation/06_builder/builder.go index 8c99ef9..550f953 100644 --- a/creation/06_builder/builder.go +++ b/creation/06_builder/builder.go @@ -1,10 +1,13 @@ package builder +import "fmt" + //ICar 汽车,我们要造车了 //ICar 车具有以下能力 type ICar interface { Speed() int Brand() string + Brief() } //ICarBuilder 造一辆车需要具有的部件 @@ -34,6 +37,14 @@ func (c *CarProto) Brand() string { return c.BrandName } +//Brief 简介 +func (c *CarProto) Brief() { + fmt.Println("this is a cool car") + fmt.Println("car wheel size: ", c.Wheel) + fmt.Println("car MaxSpeed: ", c.MaxSpeed) + fmt.Println("car Engine: ", c.Engine) +} + //CarStudio 打算通过成立造车实验室进行造车 type CarStudio struct { prototype CarProto diff --git a/creation/06_builder/builder_test.go b/creation/06_builder/builder_test.go index 63880bc..7602a8f 100644 --- a/creation/06_builder/builder_test.go +++ b/creation/06_builder/builder_test.go @@ -19,3 +19,14 @@ func TestBuilderCar(t *testing.T) { fmt.Println(car.Speed()) fmt.Println(car.Brand()) } + +func TestBuilderCarMore(t *testing.T) { + builder := NewCarStudio() + builder.Brand("land").Speed(110).Engine("bmw") + builder.Engine("man made").Brand("panda").Wheel(15) + car := builder.Build() + + fmt.Println(car.Speed()) + fmt.Println(car.Brand()) + car.Brief() +}