What is the name of this concept, and what is its Golang best practice?

Object A calls a method of Object B, with some parameters. In those parameters there is pointer back to Object A, so that B can call functionality from Object A. This is a sign of bad design, what is the name for this ?

A similar scenario is when both objects already have the pointer to each other, and it is not passed by parameters. That is also a sign of bad design.

And what is the Golang best practice in such situations ? I need a name for this concept.

In your first paragraph, it’s called a callback.

You could define interfaces so B doesn’t get/have a pointer to A (and vice versa), but it has an interface instance, which may not necessarily be *A, and provides some decoupling and flexibility

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.