Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Last active January 26, 2023 07:30
Show Gist options
  • Save arriqaaq/3421588e9db11f25b88de45c1fb819db to your computer and use it in GitHub Desktop.
Save arriqaaq/3421588e9db11f25b88de45c1fb819db to your computer and use it in GitHub Desktop.
type Car interface {
Drive() string
}
type SportsCar struct {}
func (s SportsCar) Drive() string {
return "Vroom vroom!"
}
type SUV struct {}
func (s SUV) Drive() string {
return "Rumble rumble!"
}
type CarFactory struct {
prototype Car
}
func (c *CarFactory) SetPrototype(car Car) {
c.prototype = car
}
func (c *CarFactory) Create() Car {
return c.prototype
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment