Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "strings"
- )
- type I interface {
- Haha() string
- Hoho() string
- }
- type Nhehe struct {
- N int
- }
- func NewNhehe(n int) Nhehe {
- return Nhehe{
- N: n,
- }
- }
- func (n Nhehe) Haha() string {
- return strings.Repeat("haha", n.N)
- }
- func (n Nhehe) Hoho() string {
- return strings.Repeat("hoho", n.N)
- }
- type TwoHehe struct{}
- func (n TwoHehe) Haha() string {
- return "hahahaha"
- }
- func (n TwoHehe) Hoho() string {
- return "hohohoho"
- }
- func DoHahaHoho(haho I) {
- fmt.Println(haho.Haha())
- fmt.Println(haho.Hoho())
- fmt.Println()
- }
- func main() {
- DoHahaHoho(NewNhehe(3))
- DoHahaHoho(TwoHehe{})
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement