From e485b8f6f3b5803e418d335fcf87494c1de39265 Mon Sep 17 00:00:00 2001 From: RotimiFreq Date: Mon, 10 Oct 2022 15:52:59 +0100 Subject: [PATCH] Method chaining design pattern in golang --- .../Method Chaining/Golang/Method_Chaining.go | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Creational/Method Chaining/Golang/Method_Chaining.go diff --git a/Creational/Method Chaining/Golang/Method_Chaining.go b/Creational/Method Chaining/Golang/Method_Chaining.go new file mode 100644 index 0000000..ebc1153 --- /dev/null +++ b/Creational/Method Chaining/Golang/Method_Chaining.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" +) + +type Player_Stat struct { + GamesPlayed float64 + GoalScored float64 + ShotOnTarget float64 + Assist float64 +} + +func (s *Player_Stat) GoalsRatio(goals, gamesplayed float64) *Player_Stat { + s.GoalScored = goals + s.GamesPlayed = gamesplayed + + Goalsratio := s.GoalScored / s.GamesPlayed + fmt.Printf("\nPlayer goal ratio is : %f", Goalsratio) + return s + +} + +func (s *Player_Stat) SOT_Ratio(Sot float64) *Player_Stat { + s.ShotOnTarget = Sot + sotRatio := float64(s.ShotOnTarget / s.GamesPlayed) + println(s.ShotOnTarget) + + fmt.Printf("\nThe player shot on target ratio is : %f", sotRatio) + + return s +} + +func (s *Player_Stat) AssistRatio(assist float64) { + + s.Assist = assist + + AssistRatio := s.Assist / s.GamesPlayed + + fmt.Printf("\nThe assist ratio is : %f", AssistRatio) +} + +func main() { + ps := Player_Stat{} + ps.GoalsRatio(20, 40).SOT_Ratio(55).AssistRatio(15) +}