In an interface do I always have to write the signatures literally?

If I want to use an interface that complies with the signatures of an external package, say *template.Template, should I write all its signatures literally?

type Tempi interface{
  AddParseTree(name string, tree *parse.Tree) (*template.Template, error)
  Clone() (*template.Template, error)
  DefinedTemplates() string
  Delims(left, right string) *template.Template
  [...]
}

Is there a way to inherit all the signatures with a single statement?

type Tempi interface{
  *template.Template
}

Tempi will obviously compile but it can only be used as a type constraint, I want Tempi to inherit all the signatures from *template.Template, is this possible?

Hello there, if *template.Template is a struct, then as far as I know, no. You can’t pass it into the interface. But if it has interface description in external package, then you can use it to embed into your custom one with any additions you need.

2 Likes

I tested, You can not use composition in an Interface

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.