All DTO classes come with the functionality to automatically detect whether any of the data the hold has been modified. With this functionality you can easily implement functionality like avoiding a database access or a service call when a user presses a ‘Save’-button without having modified any data.
Every DTO class that relates to a modeled display has its own
dirty flag. Every setter of such a DTO class sets
dirty = true in case the new data is different from the already available data. The DTO class that relates to a modeled layout does not have a
dirty flag but provides the method
isDirty() that checks all reachable instances of DTO classes to find out whether it can find a dirty object. The method
isDirty() returns true if it can find at least one dirty DTO instance.
The default value of
false when you create a new DTO instance.
Additionally, every DTO class has a method
This method resets all
dirty flags of all reachable DTO instances to
With this, the order of executing code to handle DTOs is as follows:
- Get the data that you want to use to fill DTO instances, e.g. from a database or a service call.
- Create DTO instances.
- Fill the DTO instances with data.
clearAllDirty()on the DTO class that corresponds to the modeled layout.