In this section, you will learn how to develop your own interfaces, This is a relatively easy process as long as you know what you want to develop.
The technique will be illustrated using the Go code of myInterface.go
, which will be presented below. The interface that will be created will help you work with geometric shapes of the plane.
The Go code of myInterface.go
follows next:
package myInterface type Shape interface { Area() float64 Perimeter() float64 }
The definition of the shape
interface is truly simple and straightforward, as it requires that you implement just two functions named Area()
and Perimeter()
, which both return a float64
value. The first function will be used for calculating the area of a shape in the plane and the second one will be used for calculating the perimeter of a shape in the plane. After that, you will need to install the myInterface.go
package and make it available to the current user. As you already know, the installation...