I know Go don't have such OO concept, but let me borrow them just to make it easier to explain.
Suppose I have a "base class" Vehicle and a "inherit class" Car, like the following:
type Vehicle struct {
wheelCount int
}
type Car struct {
Vehicle //anonymous field Vehicle
Maker string
}
In true OO, I can assign a Vehicle object into a Car object, but I haven't found a way to do that in Go. So my questions are,
- Is it possible to do that?
- Else, what's the Go way to write a "Car" constructor from a "Vehicle"? I know the canonical way is `c := Car{Vehicle{4}, "Ford"}`, but what if I have other member fields in Car, like Module etc, and I'd like only to initial the member fields from Vehicle, nothing else?
I've prepared something for you to start with,
Thanks
Ref: