I have a Class, it will be implemented to be many instances. I want to keep connections between some of the instances, and pass messages among them. In C++, I can do this like:
class A
{
A (*connections)[];
int sum;
public:
void pass(int index)
{
connections[index] -> receive(sum);
}
void receive(int input)
{
sum += input;
}
}
Then I only need to add pointers of other instances to connections[], I can pass messages among them with each other.
Currently I have to use Python doing this, but Python doesn't support pointers. I wonder what is the proper solution, or design pattern, to solve this problem?
Thank you in advance.
Aimplementation, but for the API of its instances.connections[index] -> receive(sum);is similar toconnections[index].receive(sum)in Python, butconnections[index]should be a pointer (or say a reference, not a value).