Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. package main
  2.  
  3. type Duck interface{}
  4.  
  5. type WildDuck struct{}
  6.  
  7. func NewWildDuck(duckType string) *WildDuck {
  8. if duckType != "wild" {
  9. return nil
  10. }
  11. return &WildDuck{}
  12. }
  13.  
  14. func NewDuck(duckType string) Duck {
  15. var duck Duck
  16. duck = NewWildDuck(duckType)
  17. if duck == nil {
  18. panic("Bad duck type!")
  19. }
  20. return duck
  21. }
  22.  
  23. func main() {
  24. NewDuck("wild")
  25. NewDuck("domestic")
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement