The composition of the interfaces [Golang]

Is there a way to make an interface also include methods defined by another interface in Go?

For instance:

type BasicDatabase interface { CreateTable(string) error DeleteTable(string) error } type SpecificDatabase interface { CreateUserRecord(User) error } 

I would like to indicate that the SpecificDatabase interface contains the BasicDatabase interface. Just as Go allows you to execute structure structures.

Thus, my methods can take a type that implements SpecificDatabase , but still calls CreateTable() on it.

+6
source share
1 answer

This can be done in the same way as when creating structures.

 type BasicDatabase interface { CreateTable(string) error DeleteTable(string) error } type SpecificDatabase interface { BasicDatabase CreateUserRecord(User) error } 
+14
source

Source: https://habr.com/ru/post/986937/


All Articles