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
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
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