

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Interfaces in Go
incomplete
2: Interface Implementation
incomplete
3: Interfaces Are Implemented Implicitly
incomplete
4: Interfaces Quiz
incomplete
5: Multiple Interfaces
incomplete
6: Name Your Interface Parameters
incomplete
7: Type Assertions in Go
incomplete
8: Type Switches
incomplete
9: Clean Interfaces
incomplete
10: Message Formatter
incomplete
11: Process Notifications
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Remember, interfaces are collections of method signatures. A type "implements" an interface if it has all of the methods of the given interface defined on it.
type shape interface {
area() float64
}
If a type in your code implements an area method, with the same signature (e.g. accepts nothing and returns a float64), then that object is said to implement the shape interface.
type circle struct{
radius float64
}
func (c circle) area() float64 {
return 3.14 * c.radius * c.radius
}
This is different from most other languages, where you have to explicitly assign an interface type to an object, like with Java:
class Circle implements Shape