Created
January 27, 2023 09:44
-
-
Save arriqaaq/29f002c70bf01487a8774652ab597140 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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