mirror of
https://github.com/MADTeacher/go_basics.git
synced 2025-11-29 05:36:55 +02:00
отредактирована 3 глава
This commit is contained in:
3
part_3/3.3/golang/factory/go.mod
Normal file
3
part_3/3.3/golang/factory/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module golang/factory
|
||||
|
||||
go 1.24
|
||||
19
part_3/3.3/golang/factory/main.go
Normal file
19
part_3/3.3/golang/factory/main.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golang/factory/shape"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
myShape := shape.Shape{
|
||||
Name: "Cube",
|
||||
Center: shape.Point{X: 4, Y: 5},
|
||||
}
|
||||
|
||||
fmt.Printf("%+v\n", myShape) // {Name:Cube Center:{X:4 Y:5} color:}
|
||||
myShape.SetColor("Gold")
|
||||
fmt.Printf("%+v\n", myShape) // {Name:Cube Center:{X:4 Y:5} color:Gold}
|
||||
fmt.Printf("Shape color: %v\n", myShape.GetColor()) // Shape color: Gold
|
||||
}
|
||||
20
part_3/3.3/golang/factory/shape/shape.go
Normal file
20
part_3/3.3/golang/factory/shape/shape.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package shape
|
||||
|
||||
type Point struct {
|
||||
X int
|
||||
Y int
|
||||
}
|
||||
|
||||
type Shape struct {
|
||||
Name string
|
||||
Center Point
|
||||
color string
|
||||
}
|
||||
|
||||
func (s *Shape) SetColor(color string) {
|
||||
s.color = color
|
||||
}
|
||||
|
||||
func (s *Shape) GetColor() string {
|
||||
return s.color
|
||||
}
|
||||
Reference in New Issue
Block a user