Advertisement
PaulPaulAga

Untitled

Apr 1st, 2021
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.65 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "strings"
  6. )
  7.  
  8. type I interface {
  9.     Haha() string
  10.     Hoho() string
  11. }
  12.  
  13. type Nhehe struct {
  14.     N int
  15. }
  16.  
  17. func NewNhehe(n int) Nhehe {
  18.     return Nhehe{
  19.         N: n,
  20.     }
  21. }
  22.  
  23. func (n Nhehe) Haha() string {
  24.     return strings.Repeat("haha", n.N)
  25. }
  26.  
  27. func (n Nhehe) Hoho() string {
  28.     return strings.Repeat("hoho", n.N)
  29. }
  30.  
  31. type TwoHehe struct{}
  32.  
  33. func (n TwoHehe) Haha() string {
  34.     return "hahahaha"
  35. }
  36.  
  37. func (n TwoHehe) Hoho() string {
  38.     return "hohohoho"
  39. }
  40.  
  41. func  DoHahaHoho(haho I) {
  42.     fmt.Println(haho.Haha())
  43.     fmt.Println(haho.Hoho())
  44.     fmt.Println()
  45. }
  46.  
  47. func main() {
  48.     DoHahaHoho(NewNhehe(3))
  49.     DoHahaHoho(TwoHehe{})
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement