-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Go Recipes for Developers
By :
In object-oriented languages such as Java or C++, there is the concept of an abstract method or virtual method, together with type inheritance. One effect of this feature is that if you call a method M of a base class base, then the method that runs at runtime is the implementation of M that is declared for the actual object at runtime. In other words, you can invoke a method that will be overridden by other declarations, and you just don’t know which method you are actually calling.
There are ways of doing the same thing in Go. This recipe shows how.
Let’s say you need to write a circular linked list data structure whose elements will be structs embedding a base struct:
type ListNodeHeader struct {
next Node
prev Node
list *List
} The list itself is as follows:
type List struct {
first Node
} So, the list points to the first node...