Objects in Go
The lengthy introductory material from the previous sections was the setup to lead to the discussion of objects in Go. It has been mentioned that Go was not designed to function as traditional object-oriented language. There are no object or class keywords defined in Go. So then, why are we discussing objects in Go at all? Well, it turns out that Go perfectly supports object idioms and the practice of object-oriented programming without the heavy baggage of classical hierarchies and complex inheritance structures found in other object-oriented languages.
Let us review some of the primordial features usually attributed to an object-oriented language in the following table.
Object feature |
Go |
Comment |
Object: A data type that stores states and exposes behavior |
Yes |
In Go all types can achieve this. There is no special type called a class or object to do this. Any type can receive a set of method to define its behavior, although the |