I have a question about keeping track of objects in different layers of a software application. In my application, I have objects in the domain layer (e.g. LineShape
) that are used to represent business entities, and I have corresponding objects in the presentation layer (e.g. System.Windows.Shapes.Line
) that are used to display these entities on the screen.
My question is, how do I keep the correspondence between the domain objects and the presentation objects, so that I can identify which domain object is represented by a given presentation object?
For example, if the user clicks on a System.Windows.Shapes.Line
in the user interface, how can I determine which LineShape
in the domain layer this object represents?
I have thought of a few potential solutions, but none of them seem ideal, especially for larger and more complex object models.
- One solution is to use a dictionary that maps presentation objects to domain objects. In this case, when the user clicks on a
System.Windows.Shapes.Line
, I could look up the correspondingLineShape
in the dictionary. - Another solution is to use an ID for both the presentation and domain objects. This approach has the advantage of being simple, but it seems strange to me to use IDs for every object in a domain-driven design, as IDs are typically used only for entities.
Are there any best practices or established patterns for solving this problem?