fix composition is not inheretance

This commit is contained in:
2026-10-05 16:43:26 -04:00
parent 5e93134cb2
commit f3c7ef35be
2 changed files with 47 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
module gitea.zacksolutions.dev/Zakaria/compositions
go 1.27.1
+44
View File
@@ -0,0 +1,44 @@
package main
import (
"fmt"
"path/filepath"
)
type Pair struct {
Path string
Hash string
}
func (p Pair) String() string {
return fmt.Sprintf("Hash of %s is %s", p.Path, p.Hash)
}
type PairWithLength struct {
Pair
Length int
}
func (p PairWithLength) String() string {
return fmt.Sprintf("Hash of %s is %s; length %d", p.Path, p.Hash, p.Length)
}
func (p Pair) Filename() string {
return filepath.Base(p.Path)
}
type Filenamer interface {
Filename() string
}
func main() {
p := Pair{"/urs", "0xfdfe"}
pl := PairWithLength{Pair{"/usr/bin", "0xdead"}, 13643532}
var fn Filenamer = PairWithLength{Pair{"/usr/bin", "0xdead"}, 13643532}
fmt.Println(p)
fmt.Println(fn)
fmt.Println(pl.Path)
fmt.Println(p.Filename())
}