title: Why would you want to use composition in golang?
body: <p>In the following code I show what I think is the difference between embedding (where methods get promoted) and composition (where methods are not promoted) in golang.</p>
  <p>Why would you ever want to use composition in golang?</p>
  <pre><code>type obj1Inherited struct {
      obj2
  }
  
  type obj1Composed struct {
      someobj obj2
  }
  
  type obj2 struct {
  }
  
  func (o obj2) printTest() {
      fmt.Println(&quot;obj2&quot;)
  }
  
  func main() {
      o := obj1Inherited{}
      o.printTest() //fine - printTest is promoted
  
      obj1Composed := obj1Composed{}
      obj1Composed.someobj.printTest() //fine because I'm using the composed obj
      obj1Composed.printTest() //not fine - printTest is NOT promoted
  </code></pre>