package main
import "fmt"
type Person struct {
Address string
PostCode string
JobType string
Company string
}
type PersonBuilder struct {
person *Person
}
func NewPersonBuilder() *PersonBuilder {
return &PersonBuilder{&Person{}}
}
func main() {
pb := NewPersonBuilder() //&{0xc0000b6040}
pd := &Person{"a", "b", "c", "d"} //&{a b c d}
fmt.Println(pb, pd)
}
&{0xc0000b6040} &{a b c d}
fmt.Printf("&person is: %p\n", pd)
&person is: 0xc0000bc080
https://go.dev/play/p/P2kMz-D1hsn
func main() {
pb := NewPersonBuilder()
fmt.Println(reflect.TypeOf(pb)) //*main.PersonBuilder
fmt.Printf("pb: %[1]T %[1]p\n", pb) //pb: *main.PersonBuilder 0xc0000ba018
pd := &Person{"a", "b", "c", "d"} //&{a b c d}
fmt.Println(pb, pd) //&{0xc0000bc040} &{a b c d}
}
Sprint는 어떤 때 사용되는가? (0) | 2022.03.26 |
---|---|
Quick Sort in Go (0) | 2022.03.17 |
28/2 mixture of field:value and value initializers error in Go (0) | 2022.02.28 |
27/02 Builder pattern in GO - Construct the ship's Defense Shields (4) | 2022.02.27 |
댓글 영역