Calculating a properties value

How do I calculate a properties value based on other concept’s properties in the domain model? What is the preferred way and why?
[151 byte] By [SusanE] at [2007-12-16]
# 1

In the Corona tool, the way we do it is to mark a property as read-only and custom storage.

Then we override the method GetValueForCustomStoredAttribute of the model element in question and do the calculation there.

It wouldn't be wise to rely on rules or events for this "calculated" property.

In future this will certainly change - we're still working our what it will change to.

Gareth

-

AlanCameronWills at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 2
Alan,
Could you, please, post a code snippet how to do that?
I can't find the declaration of this particular property.

TIA,
Richard

Alan Cameron Wills wrote:

In the Corona tool, the way we do it is to mark a property as read-only and custom storage.

Then we override the method GetValueForCustomStoredAttribute of the model element in question and do the calculation there.

It wouldn't be wise to rely on rules or events for this "calculated" property.

In future this will certainly change - we're still working our what it will change to.

Gareth

-

Richard3 at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 3

You don't want to store a property value that is calculated based on other information in the model. That's duplication, and if your own experience hasn't (yet) taught you this is a bad idea, I hope you won't think I'm patronising you if I suggest you trust the collected wisdom of things like database normalization and the Don't Repeat Yourself principle.

The normal change is to move the calculation of that value to the generator. If necessary, you can also add an element to the visual representation of the object that shows the calculated value (in MetaEdit+ that would be a text element whose content comes from running a generator; I don't think such a thing exists out of the box in the MS DSL tools, but no doubt you could hand-code one).

Of course, the visual representation will by default not update when the values that contribute to it are changed, especially if they are pulled in from other objects a long way off, but that's rarely a real problem.

StevenKelly at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 4
I do come from database community myself so
I'm perfectly aware of normal forms.
I'm interested in the "compute property" as a work-around
for the fact that one cannot (easily) specify/change defaults of inherited properties (see my other question
on that )

Best regards,
Richard

Steven Kelly wrote:

You don't want to store a property value that is calculated based on other information in the model. That's duplication, and if your own experience hasn't (yet) taught you this is a bad idea, I hope you won't think I'm patronising you if I suggest you trust the collected wisdom of things like database normalization and the Don't Repeat Yourself principle.

Richard3 at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...

Visual Studio

Site Classified