Getting rid of dynamic polymorphism and classes

F i L witte2008 at gmail.com
Thu Nov 8 10:36:13 PST 2012


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()
     }


More information about the Digitalmars-d mailing list