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
type Person struct { | |
Name string | |
Age int | |
} | |
func (p *Person) Greet() string { | |
return "Hello, my name is " + p.Name | |
} | |
func (p *Person) Copy() *Person { |
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
type Person struct { | |
Name string | |
Age int | |
} | |
func (p *Person) Greet() string { | |
return "Hello, my name is " + p.Name | |
} | |
originalPerson := &Person{Name: "John", Age: 30} |
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
type Person struct { | |
Name string | |
Age int | |
} | |
func (p *Person) Greet() string { | |
return "Hello, my name is " + p.Name | |
} | |
originalPerson := &Person{Name: "John", Age: 30} |
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
type Car struct { | |
Brand string | |
Model string | |
} | |
func (c *Car) Drive() string { | |
return "Vroom vroom!" | |
} | |
originalCar := &Car{Brand: "Tesla", Model: "Model S"} |
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
type Car struct { | |
Brand string | |
Model string | |
} | |
func (c *Car) Drive() string { | |
return "Vroom vroom!" | |
} | |
originalCar := &Car{Brand: "Tesla", Model: "Model S"} |
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
myCarFactory := CarFactory{} | |
myCarFactory.SetPrototype(SportsCar{}) | |
myCar := myCarFactory.Create() |
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
type Car interface { | |
Drive() string | |
} | |
type SportsCar struct {} | |
func (s SportsCar) Drive() string { | |
return "Vroom vroom!" | |
} |
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
type Car interface { | |
Drive() string | |
} | |
type SportsCar struct{} | |
func (s SportsCar) Drive() string { | |
return "Vroom vroom!" | |
} |
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
type carFactory struct {} | |
func (c carFactory) Create(carType string) Car { | |
if carType == "sports" { | |
return SportsCar{} | |
} else if carType == "suv" { | |
return SUV{} | |
} | |
return nil | |
} |
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
type Car interface { | |
Drive() string | |
} | |
type SportsCar struct {} | |
func (s SportsCar) Drive() string { | |
return "Vroom vroom!" | |
} |