An example of transferring the C ++ class hierarchy to Golang. Is it done correctly? I am trying to transfer my c ++ experience to the Go area. I'm new to Go, so not sure if the implementation is correct. In any case, it looks very ugly compared to C ++ code. Is there a nicer solution? Both solutions are executable in playground and give same result.
c++ playground: https://code.sololearn.com/c67xbW2AEWW2/#cpp
#include &lt;iostream&gt;
using namespace std;

// Abstract class
class AbstractGenerator
{
public:
    AbstractGenerator() {}
    std::string generate(std::string some_internal_data)
    {
        _some_internal_data = some_internal_data;
        return step1() + step2();
    }

protected:
    // some shared fuctions
    std::string generationHelper1(std::string s) { return s + _some_internal_data + &quot;123&quot;; }
    std::string generationHelper2(std::string s) { return s + _some_internal_data + &quot;456&quot;; }
    // abstract fucntions
    virtual std::string step1() = 0;
    virtual std::string step2() = 0;

private:
    std::string _some_internal_data;
};
// Implementation
class MyGenerator : public AbstractGenerator
{
public:
    MyGenerator() {}

protected:
    std::string step1() override { return generationHelper1(&quot;my step1&quot;) + generationHelper2(&quot;my step1&quot;); }
    std::string step2() override { return &quot;my step2&quot;; }
};

int main() {
    MyGenerator my_gen;
    AbstractGenerator* abstract_gen = &amp;my_gen;
    cout &lt;&lt; abstract_gen-&gt;generate(&quot;data&quot;);
    return 0;
}

Go playground: https://play.golang.org/p/e3iXfYar4YJ
package main

import &quot;fmt&quot;

// some shared fuctions - interface
type ImplementationHelper interface {
    generationHelper1(s string) string
    generationHelper2(s string) string
}

// abstract fucntions - interface
type Implementation interface {
    step1() string
    step2() string
}

// Public main interface
type Generator interface {
    Generate(s string) string
}

type AbstractGenerator struct {
    someInternalData string
    implementation   Implementation
}

func NewAbstractGenerator(i Implementation) *AbstractGenerator {
    g := new(AbstractGenerator)
    g.implementation = i
    return g
}
func (g *AbstractGenerator) Generate(s string) string {
    g.someInternalData = s
    return g.implementation.step1() + g.implementation.step2()
}
func (g *AbstractGenerator) generationHelper1(s string) string { return s + g.someInternalData + &quot;123&quot; }
func (g *AbstractGenerator) generationHelper2(s string) string { return s + g.someInternalData + &quot;456&quot; }

// Implementation of AbstractGenerator
type MyGenerator struct {
    basic *AbstractGenerator
}

// MyGenerator constructor
func NewMyGenerator() *MyGenerator {
    myGen := new(MyGenerator)
    myGen.basic = NewAbstractGenerator(myGen)
    return myGen
}

// Interface Generator
func (i *MyGenerator) Generate(s string) string {
    return i.basic.Generate(s)
}

// Interface Implementation
func (i *MyGenerator) step1() string {
    return i.basic.generationHelper1(&quot;my step1&quot;) + i.basic.generationHelper2(&quot;my step1&quot;)
}
func (i *MyGenerator) step2() string {
    return &quot;my step2&quot;
}

func main() {
    myGen := NewMyGenerator()

    var abstractGen Generator
    abstractGen = myGen

    fmt.Println(abstractGen.Generate(&quot;data&quot;))
}
This:
g := new(AbstractGenerator)
g.implementation = i
return g

Can be more simply written as:
return &amp;AbstractGenerator{implementation: i}