Last active
December 20, 2017 04:15
-
-
Save nvcnvn/3271863ac703d5f103098fc03b9050bf 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
func main() { | |
assasinService := &KindOfAssasinService{} | |
transporter := NewTransporter(assasinService) | |
hitman := NewHitMan(assasinService); | |
} | |
type KindOfAssasinService {} | |
func (ass *KindOfAssasinService) GetVehicle(t string) Vehicle { | |
if t == "car" { | |
return &Car{} | |
} | |
return &Tank{} | |
} | |
func (ass *KindOfAssasinService) GetWeapon(t string) Weapon { | |
if t == "gun" { | |
return &Gun{} | |
} | |
return &Dagger{} | |
} |
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 WeaponFactory interface { | |
GetWeapon(t string) Weapon | |
} | |
type Hitman struct { | |
weaponFactory WeaponFactory | |
} | |
func (h *Hitman) doHitmanStuff() { | |
h.weaponFactory.GetWeapon("gun").KickSomeAss() | |
} |
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 VehicleFactory interface { | |
GetVehicle(t string) Vehicle | |
} | |
type Transporter struct { | |
vehicle Vehicle | |
} | |
func (t *Transporter) makeOutWith(pretty Lady) { | |
// ... | |
} | |
func (t *) hitAllTheBadGuysAt(dest Desination) { | |
t.vehicle.Move(dest) | |
} | |
func NewTransporter(f VehicleFactory) *Transporter { | |
return &Transporter{ | |
vehicle: f.Getvehicle("car"), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment