I am working on a project that attempts to represent an electronic circuit. This problem doesn’t deal with circuit theory, just with connections between objects.
The problem is I need to make a connection between two objects in two different ways.
I have a Component and a Node. A component has two terminals (positive and negative), each of which connects to a node. A node can have many different terminals connected to it.
So, I can have
component1.positive = node1
But if I wanted to also do
node1.add_terminal( component1.positive )
That would just give node1 a reference to itself.
I would like to be able to have Nodes contain a collection of which terminals of which components connect to it or reference it, without having to write
node1.add_terminal( component1, "positive")
or something similar.
So, is there a way to store “component1.positive”, so that it can be followed back to a Component and the specific terminal of that component? Or is there another way to represent this many-to-one and one-to-many relationship?
EDIT:
It’s important that the Node object can tell which of the two terminals of the component it was connected to.
You can use properties. Consider this (updated):
Usage: