Let us go through a simple example of creating an abstract base class representing a rocket engine with some concrete implementations in Golang, C++ and the new Carbon language from Google. To be accurate, Carbon is not an official Google project but done by people working at Google.
Creating class or type hierarchies in the Golang, C++ and Carbon programming languages
There is no Carbon compiler presently, and the interpreter is very bare bones with a lot of missing functionality, so the code I am writing here is based on the language specification rather than being verified by a compiler. Keep that in mind as there are possible errors.
In my upcoming programming book, Julia as a Second Language, I take the reader through building a space rocket in code. The code project came about specifically to teach readers how to model type hierarchies and understand how to do object composition.
I have found this helpful example enough to replicate it in Golang code, intending to write a Go programming book with this theme someday. In this article, I will model a subset of this type of hierarchy and object composition in C++ and Carbon.
Since the whole type hierarchy example is explored over multiple chapters in my Julia book, we can only cover a small subset of it in this story. I have chosen to zoom in on the type hierarchy for rocket engines.
A rocket engine cluster is a collection of multiple engines. For instance, the Saturn V moon rocket had an engine cluster of five F1 engines in the first stage. A modern Falcon 9 rocket from SpaceX has nine Merlin engines in the first stage and a single Merlin engine in the second stage.
Defining Interfaces in Golang
The original Go code defines an abstract interface
Engine for all concrete engines
CustomeEngine to implement.