Object Identity
No edit summary
No edit summary
Line 1: Line 1:
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.
While everything starts small, some things never stop growing. Eventually, you have a big system on your hands that needs to send data here and there through the enterprise. You then start to wish that you had a particular way in which you could 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.
When importing reference data into a system, it is very important that the producing system keeps track of the objects that have been deleted. Otherwise, the importing system will have no way to know that some of the reference data it has should not exist anymore.


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.
Having these kinds of imports and exports between systems is key 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 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.
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 way to achieve the 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.
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:
This is how you can get the necessary hygiene into a system built with MDriven:
Line 13: Line 13:
[[File:Hygiene -1.png|border|frameless|184x184px]]
[[File:Hygiene -1.png|border|frameless|184x184px]]


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


[[File:Hygiene - 2.png|border|frameless|244x244px]]
[[File:Hygiene - 2.png|border|frameless|244x244px]]


In the method body for OnCreate set this ocl:<blockquote>''CreateTime:=DateTime.Now;''</blockquote><blockquote>''self.Guid.newGuid()''</blockquote>In the method body for OnUpdate set this ocl:<blockquote>''self.ChangeTime:=DateTime.Now''</blockquote>In the method body of OnDelete set this ocl:<blockquote>''let x=DeletedObj.Create in''</blockquote><blockquote>''(''</blockquote><blockquote>  ''x.DeletedGuid:=self.Guid''</blockquote><blockquote>'')''</blockquote>And voila – when you create an object of any class in your package you get a CreateTime and a GUID:
In the method body for OnCreate, set this OCL:<blockquote>''CreateTime:=DateTime.Now;''</blockquote><blockquote>''self.Guid.newGuid()''</blockquote>In the method body for OnUpdate, set this OCL:<blockquote>''self.ChangeTime:=DateTime.Now''</blockquote>In the method body of OnDelete, set this OCL:<blockquote>''let x=DeletedObj.Create in''</blockquote><blockquote>''(''</blockquote><blockquote>  ''x.DeletedGuid:=self.Guid''</blockquote><blockquote>'')''</blockquote>Voila! When you create an object of any class in your package, you get a CreateTime and a GUID:


[[File:Hygiene - 3.png|border|frameless|393x393px]]
[[File:Hygiene - 3.png|border|frameless|393x393px]]


And when you have saved the new object it gets a ChangeTime.
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:
When you delete an object, we get a new DeletedObject created with the DeletedGuid kept:


[[File:Hygiene - 4.png|border|frameless|404x404px]]
[[File:Hygiene - 4.png|border|frameless|404x404px]]


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 from 2012-03-15.
Note: The ''OnCreate'', ''OnUpdate'', and ''OnDelete'' are new methods that we will trigger if found on any class for its respective event (Create, Update, Delete). Also, see the NewGuid operation from 2012-03-15.


Also, look at the method [[OnStateChange]] for tracking changes to your objects.
Have a look at the method [[OnStateChange]] for tracking changes to your objects.
[[Category:MDriven Designer]]
[[Category:MDriven Designer]]
[[Category:View Model]]
[[Category:View Model]]
[[Category:OCL]]
[[Category:OCL]]

Revision as of 06:52, 31 January 2023

While everything starts small, some things never stop growing. Eventually, you have a big system on your hands that needs to send data here and there through the enterprise. You then start to wish that you had a particular way in which you could 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 keeps track of the objects that have been deleted. Otherwise, the importing system will have no way to know that some of the reference data it has should not exist anymore.

Having these kinds of imports and exports between systems is key 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 in order 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:

Hygiene -1.png

Set the SuperClass as the Default superclass for the package:

Hygiene - 2.png

In the method body for OnCreate, set this OCL:

CreateTime:=DateTime.Now;

self.Guid.newGuid()

In the method body for OnUpdate, set this OCL:

self.ChangeTime:=DateTime.Now

In the method body of OnDelete, set this OCL:

let x=DeletedObj.Create in

(

  x.DeletedGuid:=self.Guid

)

Voila! When you create an object of any class in your package, you get a CreateTime and a GUID:

Hygiene - 3.png

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:

Hygiene - 4.png

Note: The OnCreate, OnUpdate, and OnDelete are new methods that 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.

This page was edited 79 days ago on 02/10/2024. What links here