Information hygiene

This article was moved to MDriven Wiki Information hygiene

Everything starts up small – and some things never stops to grow. Pretty soon you have a big system on your hands that needs to send data here and there thru the enterprise. You then start to whish that you had some very exact way to identify a specific object – like a globally unique identifier – a GUID.

When importing reference data into a system, it is very important that the producing system keep tracks of the objects that has been deleted. Otherwise the importing system will have no way to know that some of the reference data it has actually should not exist any more.

Having these kinds of import and exports between systems is key to the idea of service oriented architecture SOA. When you have good access to reference data you will have no problem in letting the system you create focus on one task only – leaving maintenance of the reference data to someone else.

It is however important that the coupling between multiple systems is done loosely – so that your collected environment does not become as brittle as it will if all things require that everything else works in order to produce a result. The correct strategy is to use asynchronous connections between systems.One good way to get asynchronous discovery of new or changed data  is to have timestamps on objects.

So where is all this going? Well it is just hygiene – something that needs to be in place if you want to get a complex environment working.

This is how you can get the necessary hygiene into a system built with ECO or BoringPredictable:


Set the SuperClass as the Default super class for the package:


In the method body for OnCreate set this ocl:


In the method body for OnUpdate set this ocl:


In the method body of OnDelete set this ocl:

let x=DeletedObj.Create in

And voila – when you create an object of any class in your package you get a CreateTime and a GUID:


And when you have saved the new object it gets a ChangeTime.

And when you delete an object we get a new DeletedObject created with the DeletedGuid kept:


Note: The OnCreate,OnUpdate,OnDelete are new methods that we will trigger if found on any class for its respective event (Create,Update,Delete). Also the NewGuid operation is new from 2012-03-15.

Update: Yet another event method has been added: OnStateChange(attrib:String; oldstate:String; newstate:String) . Any class with this method signature will get called for each trigger-call that is made on the statemachine. The main intended use is audit and logging functionality. When you use state machines heavily to track important events in your business – this becomes important. The event method is NOT for stopping transitions – use guards for that. You can solve logging by implementing state effects or entry actions as well – but the OnStateChange method helps you to pull out generic logging from the state machines.

This entry was posted in Declarative, MDrivenServer, Modlr. Bookmark the permalink.

12 Responses to Information hygiene

  1. Peter Buchmann says:


    When will OnUpdate and OnDelete be called? Before UpdateDatabase or when the operation is executed on the object (like a change of a attribute)?

    • Hans Karlsen says:

      Good question. OnUpdate is called after you call UpdateDatabase but before data is sent to the database. Same for OnDelete.
      New objects that are deleted before they are saved at least once will NOT get a OnDelete or OnUpdate – since they never got that far in their lifecycle.
      Changes of attributes triggers INotifyPropertyChanged and should not be confused with OnUpdate.

      • Peter Buchmann says:


        I just took a look into this functionality. At least for OnDelete I can say: It is called when the object is deleted, no matter if it was saved before. I would hold this for the correct behaviour but it is in conflict with your last post.

  2. wangwei says:

    how can save the deleted class into deletedobj one field,for example save class as json stirng,or other.
    thank you!

    • Admin says:

      To save the complete state of the deleted object is certainly possible – and as you suggest json format might be good. How to translate the objects state into json is a bigger question – it all depends – embed links or not, embed delayed fetched attributes or not etc.

  3. wangwei says:

    another question ,you know ,we need recodor deleted object,and I need know who delete the object. So we must save the current login user info, but how to use this inforation by ocl in the design model ? ondelete() can have param?
    thank you!

    • hans says:

      The OnDelete cannot have parameters – but consider having a Singleton class in your model. Call it “MySystem”, have a derived association to the logged in user. Then your OnDelete can look like:

  4. guest00 says:

    CO, thanks a lot for this functionality!

  5. Pawel Pawlow says:

    Will you post a new production version with this functionality?

  6. Peter Buchmann says:


    I also like the new methods
    partial void ObjectFetched();
    partial void PreDelete(ref System.Boolean canDelete);
    very much but what is if a object is created and has to be cleaned up and then a undo/redo is called.

    Is there a way to be informed when the object is undone/redone?

  7. Efim Mett says:

    Hi Peter,

    have you seen this discussion about Predelete and Undo/Redo?

  8. Lars says:

    A note on OnUpdate(). It’s run when updating an object before it’s deleted, so in your OnUpdate if you do something that isn’t allowed on an object marked for deletion, use: “if self.existing then”… to only run your code when your object is alive.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.