Skip to content

Instantly share code, notes, and snippets.

@didi1246888
Created March 11, 2022 02:14
Show Gist options
  • Save didi1246888/519560fdee9f025e5932b51a1cd209a4 to your computer and use it in GitHub Desktop.
Save didi1246888/519560fdee9f025e5932b51a1cd209a4 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type Birds interface { // Distill common methods
fly()
}
type Dove struct {
}
type Eagle struct {
}
func (d *Dove) fly() { // Encapsulation method
fmt.Println("Pigeons are flying")
}
func (e *Eagle) fly() { // Encapsulation method
fmt.Println("Eagle is flying")
}
func main() {
var b Birds // Polymorphic abstract interface
dove := Dove{}
eagle := Eagle{}
b = &dove
b.fly() // Pigeons are flying
b = &eagle
b.fly() // Eagle is flying
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment