Consistency Over Time and Integration Using a Default Superclass to Provide Object Create Time, Change Time, Deletion Logging, Object Lifetime Logs, and Good API IDs
While everything starts small, some things never stop growing. Eventually, you end up with a big system that needs to send data here and there through the enterprise. You then start to wish you had a particular way to identify a specific object – like a globally unique identifier – a GUID.
When importing reference data into a system, the producing system must keep track of the objects that have been deleted. Otherwise, the importing system will have no way to realize that some of the reference data should not exist anymore.
Having these kinds of imports and exports between systems is vital to the idea of service-oriented architecture SOA. When you have access to reference data, you will have no problem letting the system you create focus on one task only – leaving the 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 to produce a result. The correct strategy is to use asynchronous connections between systems. One way to achieve the asynchronous discovery of new or changed data is to have timestamps on objects.
Where is all this going? Well, it is 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 MDriven:
Set the SuperClass as the Default superclass for the package:
self.Guid.newGuid()In the method body for OnUpdate, set this OCL:
self.ChangeTime:=DateTime.NowIn the method body of OnDelete, set this OCL:
let x=DeletedObj.Create in
)Voila! When you create an object of any class in your package, you get a CreateTime and a GUID:
When you have saved the new object, it gets a ChangeTime.
When you delete an object, we get a new DeletedObject created with the DeletedGuid kept:
Note: The OnCreate, OnUpdate, and OnDelete are new methods we will trigger if found on any class for its respective event (Create, Update, Delete). Also, see the NewGuid operation from 2012-03-15.
Have a look at the method OnStateChange for tracking changes to your objects.