Go Interfaces: Difference between revisions
Jump to navigation
Jump to search
Line 5: | Line 5: | ||
=Overview= | =Overview= | ||
An interface is a type declaration that defines a ''method set''. A method set is a list of methods a type must have in order to ''implement'' the interface. | |||
<font color=red>Can only structs be interfaces, or there are other things that can be interfaces?</font> | <font color=red> | ||
* Interfaces are not types? | |||
* Can only structs be interfaces, or there are other things that can be interfaces? | |||
</font> | |||
=Declaration= | =Declaration= |
Revision as of 17:08, 30 March 2016
Internal
Overview
An interface is a type declaration that defines a method set. A method set is a list of methods a type must have in order to implement the interface.
- Interfaces are not types?
- Can only structs be interfaces, or there are other things that can be interfaces?
Declaration
The interface declaration is introduced by the type keyword, to indicated that this is a user-defined type, followed by the interface name and the keyword interface. Unlike in the struct's case, we don't define fields but a method set. The method set is a list of methods
type MyInterface interface { functionName1() return_type functionName2() return_type ... }