Created
March 11, 2022 02:14
-
-
Save didi1246888/519560fdee9f025e5932b51a1cd209a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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