where is the indication that we are implementing that interface?
Hi, Below is the example code which explains basic interfaces
without this interface also, above program giving correct output,
then what use of interface here , and where is the indication that we are implementing that interface?
package main
import "fmt"
type Guitarist interface {
// PlayGuitar prints out "Playing Guitar"
// to the terminal
PlayGuitar()
}
type BaseGuitarist struct {
Name string
}
type AcousticGuitarist struct {
Name string
}
func (b BaseGuitarist) PlayGuitar() {
fmt.Printf("%s plays the Bass Guitar\n", b.Name)
}
func (b AcousticGuitarist) PlayGuitar() {
fmt.Printf("%s plays the Acoustic Guitar\n", b.Name)
}
func main() {
var player BaseGuitarist
player.Name = "Paul"
player.PlayGuitar()
var player2 AcousticGuitarist
player2.Name = "Ringo"
player2.PlayGuitar()
}
without this interface also, above program giving correct output,
type Guitarist interface {
// PlayGuitar prints out "Playing Guitar"
// to the terminal
PlayGuitar()
}then what use of interface here , and where is the indication that we are implementing that interface?
No any search results
You already invited:
0 Answers