This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 Dog struct { | |
| Name string | |
| Age int | |
| Breed string | |
| } | |
| func NewDog(name string) *Dog { | |
| return &Dog{ | |
| Name: name, | |
| Age: 0, |