On Sun, Sep 2, 2012 at 6:29 PM, ChrisLu <
chri...@gmail.com> wrote:
> Thanks for replying! My concern is that if Node is an interface, I need to
> put the implementation of AddChild() to each of the struct Rack and
> DataCenter.
AddChild() seems like it would be a two line method not exactly a
worrying amount of code duplication.
But you can just do this.
type Node interface{
AddChild(Node)
}
type Element struct{
parent Node
children []Node
}
func (*Element) AddChild(Node){}
type Server struct {
Element
ipAddress string
...
}
type Rack struct {
Element
ipAddressRange string
...
}
type DataCenter struct {
Element
ipAddressRange string
...
}
Server, Rack, DataCenter all satisfy the Node interface.
--
=====================
http://jessta.id.au