From e5041f6923042185275d1faa9a65a7dd5d1053e7 Mon Sep 17 00:00:00 2001 From: "Muhammad, Hammad" <muhammad@nisum.com> Date: Fri, 3 Mar 2023 15:39:22 +0500 Subject: [PATCH] added code to force to implement all interface functions --- input_file.txt | 1 - main.go | 40 ++++++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) delete mode 100644 input_file.txt diff --git a/input_file.txt b/input_file.txt deleted file mode 100644 index 8a894f3..0000000 --- a/input_file.txt +++ /dev/null @@ -1 +0,0 @@ -Hello World !!! From the file \ No newline at end of file diff --git a/main.go b/main.go index 1362fea..04838d4 100644 --- a/main.go +++ b/main.go @@ -1,28 +1,32 @@ package main -import ( - "bufio" - "fmt" - "os" -) +import "fmt" -func main() { - fileName := os.Args[1] +type ShapeCalculator interface { + Area() int + Perimeter() int +} - f, err := os.Open(fileName) - if err != nil { - fmt.Println("Error : ", err) - os.Exit(1) - } +type Rectangle struct { + Width int + Height int +} - defer f.Close() +func (r *Rectangle) Area() int { + return r.Width * r.Height +} - scanner := bufio.NewScanner(f) +// func (r *Rectangle) Perimeter() int { +// return r.Width * r.Height +// } - for scanner.Scan() { +// uncomment the following line to guarantee that Implementation implements all methods of SomeInterface +// var _ ShapeCalculator = (*Rectangle)(nil) // ↠this is the line - fmt.Println(scanner.Text()) +func main() { + rect := &Rectangle{ + Width: 10, + Height: 3, } + fmt.Println(rect.Area()) } - -//Execute with file_name as service argument -- 2.18.1