title: Object Factory in golang
body: <p>I am a new to golang. I need to design a function to create object of differing types based on input. But I failed to figure out how to design the interface. Here comes my code: </p>
  
  <pre><code>package main
  
  import (
      "fmt"
  )
  
  type AA struct{
      name string
  }
  
  func (this *AA) say(){
      fmt.Println("==========&gt;AA")
  }
  type BB struct{
      *AA
      age int
  }
  func (this *BB) say(){
      fmt.Println("==========&gt;BB")
  }
  
  func ObjectFactory(type int) *AA {
      if type ==1 {
          return new(AA)
      }else{
          return new(BB)
      }
  }
  
  func main() {
      obj1 := ObjectFactory(0)
      obj1.say()
      obj2 := ObjectFactory(0)
      obj2.say()
  }
  </code></pre>
  
  <p>The compiler tells me error no matter I ask ObjectFactory return *AA or interface{}.  How can I make it work?</p>