Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Created January 27, 2023 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arriqaaq/29f002c70bf01487a8774652ab597140 to your computer and use it in GitHub Desktop.
Save arriqaaq/29f002c70bf01487a8774652ab597140 to your computer and use it in GitHub Desktop.
package network
type NetworkElement interface {
// methods to interact with the element
GetName() string
GetType() string
}
type Router struct {
name string
model string
}
func (r *Router) GetName() string {
return r.name
}
func (r *Router) GetType() string {
return "Router"
}
type Switch struct {
name string
model string
}
func (s *Switch) GetName() string {
return s.name
}
func (s *Switch) GetType() string {
return "Switch"
}
type Network struct {
elements []NetworkElement
}
func (n *Network) AddElement(elem NetworkElement) {
n.elements = append(n.elements, elem)
}
func (n *Network) GetElements() []NetworkElement {
return n.elements
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment