Multiple methods support in Go interface

Why I cannot declare multiple methods with different arguments in Go interface? I think it is an important feature. My following code is getting wrong. Am I implementing it wrong or is there any way to implement it. It would be also helpful if I get coding suggestion to do that.

package main

import (
	"fmt"
)

type person struct {
}

type human interface {
	speak()
	speak(s string)
}

func (p person) speak() {
	fmt.Println("I have no words to say !!!")
}

func (p person) speak(word string) {
	fmt.Println("I have my words: ", word)
}

func saySomething(h human) {
	h.speak()
	h.speak("I am man.")
}

func main() {

	var p person

	saySomething(p)
}

In a object oriented language like C# the following code is valid.

using System;

namespace Example5
{
    interface IHuman
    {
        void speak();
        void speak(string word);
    }

    public class Man: IHuman
    {
        public void speak()
        {
            Console.WriteLine("I have no words to say!!!");
        }

        public void speak(string words)
        {
            Console.WriteLine("I have my words: {0}", words);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Man m = new Man();

            m.speak();
            m.speak("I am a man.");
        }
    }
}

Method overloading is not supported in Go: https://golang.org/doc/faq#overloading

I think the preferred style is to write methods with different names, like:

type human interface {
	speak()
	speakString(s string)
}

You could use variadic functions: https://golangdocs.com/variadic-functions-in-golang

type human interface {
    speak(args ...string)
}
1 Like