vendredi 13 novembre 2020

How to edit and monitor changes in a complex Datamodel

I'm working on an Editor-GUI (C#, WPF, Windows-Desktop) for a quite complex domain model. The domain model consists of many different node types mainly coupled in a hierarchie. Also it is possible to create links/references from one object to another (which can be 1:m). You could imagine it as a kind of syntax tree with Class/Method definitions and calls to that methods (this is just a rought equivalent). At the moment the model is represented in-memory by different classes.

Now my problem is, how to monitor changes in the model, so that I can update different components of my gui and track internal states like "model has changed", trigger validation etc.

At the moment I'm using a mix of edit-functions that trigger some events to inform others and in some places the INotifyChanged-Logic from .NET/WPF.

In the end this works not very well and consise, especially for my linked objects - they have no hard reference inside the model, they are referenced by an identifier. Additionally I have to pollute my domain-model with all those notify-change logic, which ties this very tight to the framework.

At the moment I see 3 possible solutions:

  1. Strictly pass all edits through an Editor-Service, so that could inform all other components/subscribers in an unified way. Cons: If you forget to use the service and edit an object "directly" no one will get informed, and editing simple properties might become cumbersome.

  2. Use INotify... everywhere and create hard links for references. Cons: this will make the domain model even more complex and every Object still has to inform some kind of message-broker so that other components can be updated.

  3. Use a message-based approach like "Change property XYZ on Object with ID 123" and send this message to all components and objects, and someone feels responsible to do that. Cons: This will create an insane overhead of Edit-Message-Classes and one will loose many possibilities concerning type-safety and refactoring.

So is there some best-practice way to edit a complex model and monitor model-changes?

cheers

Aucun commentaire:

Enregistrer un commentaire