Commit e5041f69 authored by Muhammad, Hammad's avatar Muhammad, Hammad

added code to force to implement all interface functions

parent a8b8fe71
Hello World !!! From the file
\ No newline at end of file
package main package main
import ( import "fmt"
"bufio"
"fmt"
"os"
)
func main() { type ShapeCalculator interface {
fileName := os.Args[1] Area() int
Perimeter() int
}
f, err := os.Open(fileName) type Rectangle struct {
if err != nil { Width int
fmt.Println("Error : ", err) Height int
os.Exit(1) }
}
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment