That's essentially how Go is designed:

    type Shape interface {
        draw()
    }

    type Circle struct { ... }
    type Square struct { ... }

    func (c *Circle) draw() { ... }
    func (s *Square) draw() { ... }

    func main() {
        var shape Shape
        var circle Circle
        var square Square

        shape = circle
        shape.draw() // circle.draw()

        shape = square
        shape.draw() // square.draw()
    }

Reply via email to