News for hackers. Stuff that matters.
Re:Is Go an Object-Oriented Language? by jnks on Monday June 09, 2014 @12:42PM (#7869189)
The author of this blog post is a little confused about embedded structs. His examples of has-a and is-a are both has-a's, and the syntax change involved (leaving off a name for the embedded type) doesn't actually do anything.

  type Person struct {
     Name string
     Address Address
  }
is equivalent to

  type Person struct {
     Name string
     Address
  }
And in fact, these are equivalent too:

  p.Address.Zip = "01313"

  p.Zip = "01313"
http://play.golang.org/p/aKH3YxT5Mb

Go doesn't really support is-a for structs, as pointed out elsewhere in the comments here. Interface implementation is the only way to get the sort of "this type can be substituted for this other type" idea that is-a inheritance provides in other languages.

There are no comments on this comment yet.