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.
48 lines
726 B
48 lines
726 B
4 years ago
|
package bridage
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
type Draw interface {
|
||
|
DrawCircle(radius, x, y int)
|
||
|
}
|
||
|
|
||
|
type RedCircle struct {
|
||
|
}
|
||
|
|
||
|
func (r *RedCircle) DrawCircle(radius, x, y int) {
|
||
|
fmt.Printf("Red :: radius=%d, x=%d, y=%d\n", radius, x, y)
|
||
|
}
|
||
|
|
||
|
type YellowCircle struct {
|
||
|
}
|
||
|
|
||
|
func (r *YellowCircle) DrawCircle(radius, x, y int) {
|
||
|
fmt.Printf("Yellow :: radius=%d, x=%d, y=%d\n", radius, x, y)
|
||
|
}
|
||
|
|
||
|
type Shape struct {
|
||
|
draw Draw
|
||
|
}
|
||
|
|
||
|
func (s *Shape) Shape(d Draw) {
|
||
|
s.draw = d
|
||
|
}
|
||
|
|
||
|
type Circle struct {
|
||
|
shape Shape
|
||
|
x int
|
||
|
y int
|
||
|
radius int
|
||
|
}
|
||
|
|
||
|
func (c *Circle) Constructor(radius, x, y int, draw Draw) {
|
||
|
c.radius = radius
|
||
|
c.x = x
|
||
|
c.y = y
|
||
|
c.shape.Shape(draw)
|
||
|
}
|
||
|
|
||
|
func (c *Circle) Draw() {
|
||
|
c.shape.draw.DrawCircle(c.radius, c.x, c.y)
|
||
|
}
|