I've been thinking about a simple software design problem. Imagine I am writing a web application to edit a tree of objects. Each node of this tree has an ID property that is filled in when the node object is POSTed to the backend. A user can create a tree hierarchy with multiple nodes before anything is sent to this backend, leaving all nodes with an empty ID field.
Now imagine that whenever I select a node of the tree in this application, the node object is passed to a method of a class that wants to associate different objects with individual nodes of a tree in an internal dictionary. Suppose I, for some reason, cannot depend on reference equality. Is there then a better way to identify unique nodes than giving them a temporary ID that the backend should ignore?
I don't see anything wrong with using temporary IDs that are ignored on the server, but I want to avoid changing our model classes. Another option I can think of in this particular context would be extracting the position of the node in the tree with some representation and using this as a key for the dictionary. While this would work, it is mildly complex to implement and not very efficient.