From e1921c29a838c95519d61b8da98a97a7d4642203 Mon Sep 17 00:00:00 2001 From: Nikhil Thomas Date: Fri, 24 Mar 2023 14:43:59 -0400 Subject: [PATCH] Replace interface reference with Composition Replace reference to `Department` inferface with reference to `DepartmaneBase` struct. In the existing code, DepartmentBase is unused. Signed-off-by: Nikhil Thomas --- chainOfResponsibility/cashier.go | 4 ++-- chainOfResponsibility/departmentBase.go | 2 +- chainOfResponsibility/doctor.go | 4 ++-- chainOfResponsibility/medical.go | 6 +++--- chainOfResponsibility/reception.go | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/chainOfResponsibility/cashier.go b/chainOfResponsibility/cashier.go index b64e7fc..5a4f155 100644 --- a/chainOfResponsibility/cashier.go +++ b/chainOfResponsibility/cashier.go @@ -3,14 +3,14 @@ package main import "fmt" type Cashier struct { - next Department + DepartmentBase } func (c *Cashier) execute(p *Patient) { if p.paymentDone { fmt.Println("Payment Done") } - fmt.Println("Cashier getting money from patient patient") + fmt.Println("Cashier getting money from patient:", p.name) } func (c *Cashier) setNext(next Department) { diff --git a/chainOfResponsibility/departmentBase.go b/chainOfResponsibility/departmentBase.go index a0f1e72..a42d1df 100644 --- a/chainOfResponsibility/departmentBase.go +++ b/chainOfResponsibility/departmentBase.go @@ -1,5 +1,5 @@ package main type DepartmentBase struct { - nextDepartment Department + next Department } diff --git a/chainOfResponsibility/doctor.go b/chainOfResponsibility/doctor.go index edf99a3..8ae4266 100644 --- a/chainOfResponsibility/doctor.go +++ b/chainOfResponsibility/doctor.go @@ -3,7 +3,7 @@ package main import "fmt" type Doctor struct { - next Department + DepartmentBase } func (d *Doctor) execute(p *Patient) { @@ -12,7 +12,7 @@ func (d *Doctor) execute(p *Patient) { d.next.execute(p) return } - fmt.Println("Doctor checking patient") + fmt.Println("Doctor checking patient:", p.name) p.doctorCheckUpDone = true d.next.execute(p) } diff --git a/chainOfResponsibility/medical.go b/chainOfResponsibility/medical.go index e255790..ae54112 100644 --- a/chainOfResponsibility/medical.go +++ b/chainOfResponsibility/medical.go @@ -3,16 +3,16 @@ package main import "fmt" type Medical struct { - next Department + DepartmentBase } func (m *Medical) execute(p *Patient) { if p.medicineDone { - fmt.Println("Medicine already given to patient") + fmt.Println("Medicine already given to patient:", p.name) m.next.execute(p) return } - fmt.Println("Medical giving medicine to patient") + fmt.Println("Medical giving medicine to patient:", p.name) p.medicineDone = true m.next.execute(p) } diff --git a/chainOfResponsibility/reception.go b/chainOfResponsibility/reception.go index e79a661..cd8c291 100644 --- a/chainOfResponsibility/reception.go +++ b/chainOfResponsibility/reception.go @@ -3,7 +3,7 @@ package main import "fmt" type Reception struct { - next Department + DepartmentBase } func (r *Reception) execute(p *Patient) { @@ -12,7 +12,7 @@ func (r *Reception) execute(p *Patient) { r.next.execute(p) return } - fmt.Println("Reception registering patient") + fmt.Println("Reception registering patient:", p.name) p.registrationDone = true r.next.execute(p) }