Who would walk his dog on a file path?
Seriously.

There os no need to technically forbid something
nobody will do. Someone who is not willing to read
or incapable of understand your documentation of
the interface won't be able to use it properly anyway. 

Go is not done through "Ctrl+Space driven development"
like e.g. Java where it seems a common strategy to write code
like: "Lets see what methods we have at hand and and which
classes would match here and use anyone looking suitable
from the autocompletion dropdown. Repeat until we get something
we can return. Maybe add a loop or and if-else."

And if you really want to limit the implementations: Add a private
method to the interface.

To find all type implementing something use golang.org/x/tools/cmd/guru

V.


On Thursday, 9 August 2018 07:21:55 UTC+2, Ally Dale wrote:
>
> Hi everyone,
> I have some confusion about GO's interface:
> 1. Some different interface but with the same signature
> I have put an example here: 
> https://github.com/vipally/glab/blob/master/lab12/walk_test.go
> The confusion is, there are two different interface filepath.Walker and 
> pet.Walker.
> filepath.Walker is designed for "visit all files of a filepath"
> pet.Walker is designed for "walk action of animals"
> But unfortunately, both signature is the same:
> type Walker interface {
>  Walk()
> }
>
> But in go syntax, the follow usage is legal:
> var petWalker pet.Walker
> petWalker = &filepath.FilePath{}
> petWalker.Walk()
>
> But it's obviously that this usage is out of plan.
> 2. Cannot find all types that has implements an interface
> Go tools is hard to find type pet.Dog and pet.Cat through pet.Walker,
> Because there is no declarations of the relations between them.
>
> Maybe this outter-declaration can solve this problem?
> //declare which types has implements this interface
> implements pet.Walker{
>  *pet.Dog
>  *pet.Cat
> }
> //declare this type has implement any interfaces
> implements *filepath.FilePath{
>   filepath.Walker
>   filepath.Reader
> }
>
>
>
>
> Ally.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to