From f3c7ef35bef8eceaea78de39b86eba16beaf6445 Mon Sep 17 00:00:00 2001 From: Zakaria Date: Mon, 5 Oct 2026 16:43:26 -0400 Subject: [PATCH] fix composition is not inheretance --- composition/go.mod | 3 +++ composition/main.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 composition/go.mod create mode 100644 composition/main.go diff --git a/composition/go.mod b/composition/go.mod new file mode 100644 index 0000000..526a3d4 --- /dev/null +++ b/composition/go.mod @@ -0,0 +1,3 @@ +module gitea.zacksolutions.dev/Zakaria/compositions + +go 1.27.1 diff --git a/composition/main.go b/composition/main.go new file mode 100644 index 0000000..eeab1ec --- /dev/null +++ b/composition/main.go @@ -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()) +}