Suppose I have a class
Object
which can send or receive some data:
1 2 3 4 5 6 7 8 9
|
class Object
{
protected:
int data;
public:
void SendData();
void ReceiveData();
};
|
Having two instances of this class
obj1
and
obj2
I want to connect them in some way. I would like to have this connection with the following properties:
1) For a given object it should be possible to connect as many as needed other objects to it.
2) Through this connection it should be possible to transport some data.
3) If needed each object should know about all of its connections. I.e. to what objects it is connected with and what objects are connected with it.
I do not ask writing a whole code for me. Just ideas what could I use to reach this.
EDIT:
My objects represent neurons. Each of them can be connected with each other. Each neuron can throw some number. This number is spreading out of all neurons that connected to this neuron. Connected neurons are getting this number with some weight which is also a number. So each connection is individual, it says how strong the connections between two given neurons. Eventually we have something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class Connection
{
protected:
Neuron* in;
Neuron* out;
double weight;
public:
Connection( Neuron* inNr, Neuron* outNr, double weight ) {
//do some stuff with neurons;
}
//some members
};
|
Then in
Neuron
I could just store all connections:
1 2 3 4 5 6 7 8
|
class Neuron
{
protected:
vector<Neuron*> inConnections;//those neurons which I connected to
vector<Neuron*> outConnections;//those neurons which are connected to me
public:
//some members
};
|
I could fill this connections inside
Connection
constructor.
This approach is full of design flaws.
I hope it helps to understand what I want.