The usual way is to use a composition:
type Point struct { x int y int } type CoordinatePoint struct { Point other stuff } type CartesianPoint struct { Point Other methods and fields that aren't relevant }
Syntax
Go makes this composition more like inheritance in other languages. You can, for example, do this:
cp := CoordinatePoint{} cp.x = 3 log.Println(cp.x)
And you can call functions with the Point as parameter with
doAThingWithAPoint(cp.Point)
For your points to be transferred interchangeably, you will need to define an interface
type Pointer interface { GetPoint() *Point } func (cp CoordinatePoint) GetPoint() *Point { return &cp.Point }
Then you can define functions using Pointer :
func doSomethingWith(p Pointer) { log.Println(p.GetPoint()) }
Another solution will be based on an interface defining GetX , SetX , GetY and SetY , but I personally find this approach much more difficult and more detailed than necessary.
source share