All struct methods must be placed in the same package. They can be stored in different files.
If we want to extend packages provided by the other developers, what to do? In other OOP languages, we could inherit the original classes, but there’s no inheritance in Go.
How to extend system types or 3rd party types?
In Go, there are two solutions:
Use compositions
Define alternative names
Use Composition
In our TreeNode data structure, the Traverse method uses in-order traversal.
If we want to implement a post-order traversal, we can refactor the following: