Исходники и презентации

This commit is contained in:
2025-05-23 07:26:39 +03:00
parent aa948179d5
commit 02d8430a3a
514 changed files with 13773 additions and 0 deletions

View File

@ -0,0 +1,51 @@
package main
import "fmt"
type Square struct{}
func (s *Square) Area() float64 {
return 0.0
}
func (s *Square) Perimeter() float64 {
return 0.0
}
const (
AreaMethod = iota
PerimeterMethod
)
type Interface struct {
methods [2]func() float64
}
func NewInterface(square *Square) Interface {
return Interface{
methods: [2]func() float64{
AreaMethod: square.Area,
PerimeterMethod: square.Perimeter,
},
}
}
func (i *Interface) Area() float64 {
return i.methods[AreaMethod]()
}
func (i *Interface) Perimeter() float64 {
return i.methods[PerimeterMethod]()
}
func main() {
// static dispatch
square := &Square{}
fmt.Println(square.Area())
fmt.Println(square.Perimeter())
// dynamic dispatch
iface := NewInterface(square)
fmt.Println(iface.Area())
fmt.Println(iface.Perimeter())
}