Beginning Programming Lesson 05
Inheritance, Interfaces, and Type Assertion
We created complex data types (structs/classes), but what if we wanted to create another struct that expands upon another? Or you wanted to create a number of different structs that play by a certain set of rules. The example code for today can be found here.
package main import ( "fmt" "math" ) type Polygon interface { Shape() string Perimeter() float64 Area() float64 } type Rectangle struct { Length float64 Height float64 } func (r Rectangle) Perimeter() float64 { return 2*r.
[Read More]