Author Topic: Inheritance Shape-Script between Stereotyps  (Read 6782 times)

Eran Peleg

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Inheritance Shape-Script between Stereotyps
« on: February 04, 2021, 02:21:55 am »
Hi
I have a profile model with Stereotype (ST) A, B, C.  A is an abstract ST, while both B and C are inherited from A.  I would like to run the same Shape-Script in B and C.  So, I tried to put the script in A and let it run in B and C.  It doesn't ... what should I specify in B and C in order to run A's script on Elements with B or C ST?

Thanks
Eran

qwerty

  • EA Guru
  • *****
  • Posts: 12263
  • Karma: +346/-285
  • I'm no guru at all
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #1 on: February 04, 2021, 05:21:33 am »
IIRC inheritance does not work for shape script. You would need to copy the shape scripts across the inheriting stereotypes.

q.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 7921
  • Karma: +205/-127
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #2 on: February 04, 2021, 05:04:28 pm »
IIRC inheritance does not work for shape script. You would need to copy the shape scripts across the inheriting stereotypes.

q.
q is correct, not only does inheritance not work, but you can't even call common routines.  We have to duplicate the same script fragments across each stereotype!

a REAL PITA!

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Takeshi K

  • EA User
  • **
  • Posts: 391
  • Karma: +15/-1
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #3 on: February 05, 2021, 12:12:58 pm »
Hello all,

I tried the following on the latest build, and it seems to work fine:
- add two <<stereotype>> elements A and B, and add a <<metatype>> of Class
- connect A and the Class metatype by Extension
- define a ShapeScript to A
- connect A and B by Generalization (A is parent)

When I drag&drop A or B from the Toolbox, both are drawn as the defined ShapeScript.

HTH,
--
t-kouno

qwerty

  • EA Guru
  • *****
  • Posts: 12263
  • Karma: +346/-285
  • I'm no guru at all
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #4 on: February 05, 2021, 07:28:55 pm »
Hmm. Interesting. I made a test with 13.5 where the inheritance now worked. Pretty sure it didn't with the same version a short time before since we assumed it to work but did not why we copied scripts. I would guess this is some kind of random behavior which would not surprise me. Anyhow, I have to have a close look.

q.
« Last Edit: February 05, 2021, 08:23:26 pm by qwerty »

Jayson

  • EA User
  • **
  • Posts: 311
  • Karma: +1/-0
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #5 on: February 05, 2021, 07:46:42 pm »
This IS a new (to me) development as I remember several years ago trying the same thing (and failing)

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 7921
  • Karma: +205/-127
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #6 on: February 05, 2021, 08:30:38 pm »
Hello all,

I tried the following on the latest build, and it seems to work fine:
- add two <<stereotype>> elements A and B, and add a <<metatype>> of Class
- connect A and the Class metatype by Extension
- define a ShapeScript to A
- connect A and B by Generalization (A is parent)

When I drag&drop A or B from the Toolbox, both are drawn as the defined ShapeScript.

HTH,
Hi Takeshisan,

Do you mean they were drawn with the same shapes?  I haven't tried it as I'm in transit.  I think what we are after is being able to extend the shapescript (i.e. add additional renderings) in the descendent.

There may be some utility in the ability to reuse the same shapescript in the descendants, but it's not true inheritance.  As you know, inheritance formally requires either a change in attributes or methods - otherwise, it is just a restriction.

Paolo
« Last Edit: February 05, 2021, 08:34:10 pm by Paolo F Cantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

qwerty

  • EA Guru
  • *****
  • Posts: 12263
  • Karma: +346/-285
  • I'm no guru at all
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #7 on: February 05, 2021, 08:35:28 pm »
There's definitely something fishy. I created  test stereo like above and switching the stereo manually showed inheritance fro the script. BUT when trying to add this "stand alone" stereo (as I did not any extends relation) it does not show up in the toolbox (you just see the «» symbol). You can probably say: works as designed - by Sparx.

q.

Takeshi K

  • EA User
  • **
  • Posts: 391
  • Karma: +15/-1
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #8 on: February 08, 2021, 11:54:40 am »
Quote
Do you mean they were drawn with the same shapes?  I haven't tried it as I'm in transit.  I think what we are after is being able to extend the shapescript (i.e. add additional renderings) in the descendent.

Hi Paolo,

I am sorry I misunderstood the theme. My understanding is defining Stereotype (ST) A, B, C (A is an abstract ST, while both B and C are inherited from A) and running the same Shape-Script in B and C. I did not think to extend the shapescript (i.e. add additional renderings).

Sorry, please ignore my comment.
--
t-kouno

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7536
  • Karma: +94/-17
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #9 on: February 08, 2021, 03:17:53 pm »
There may be some utility in the ability to reuse the same shapescript in the descendants, but it's not true inheritance.  As you know, inheritance formally requires either a change in attributes or methods - otherwise, it is just a restriction.

Why do you say that inheritance requires a change? You could argue that it's not meaningful if you don't add/change something, but that's not part of the definition.

In any case.. with the following shape scripts you can re-use the base and add an additional rendering.

A
Code: [Select]
shape main{
rectangle(0,0,100,100);
println("#name#");
}

B
Code: [Select]
shape main{
drawparentshape();
ellipse(10,10,30,30);
}

C
Code: [Select]
decoration x
{
moveto(0,0);
lineto(100,100);
moveto(100,0);
lineto(0,100);
}

There are limitations. There is no allowance for overriding a decoration used in the base with a new one in the specialized stereotype.

In UML terms, the main script is redefinable. All decorations are added to the collection.
Eve

support@sparxsystems.com

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 7921
  • Karma: +205/-127
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #10 on: February 08, 2021, 05:26:34 pm »
There may be some utility in the ability to reuse the same shapescript in the descendants, but it's not true inheritance.  As you know, inheritance formally requires either a change in attributes or methods - otherwise, it is just a restriction.

Why do you say that inheritance requires a change? You could argue that it's not meaningful if you don't add/change something, but that's not part of the definition.

In any case.. with the following shape scripts, you can re-use the base and add an additional rendering.

A
Code: [Select]
shape main{
rectangle(0,0,100,100);
println("#name#");
}

B
Code: [Select]
shape main{
drawparentshape();
ellipse(10,10,30,30);
}

C
Code: [Select]
decoration x
{
moveto(0,0);
lineto(100,100);
moveto(100,0);
lineto(0,100);
}
There are limitations. There is no allowance for overriding a decoration used in the base with a new one in the specialized stereotype.

In UML terms, the main script is redefinable. All decorations are added to the collection.

(my emphasis)
Thanks, Eve for the information, definitely food for thought here!

As to inheritance requiring a change, I think Bertrand Meyer in OOSC2 makes that point.  But in any case, if inheritance means "X is a type of Y" but X is no different from Y then "X IS a Y" not "a type of" Y.  Difference (as a requirement) is implied.

I'll have a play with your example (when time and resources permit) and see how the uses you describe would be useful.

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 7921
  • Karma: +205/-127
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #11 on: February 09, 2021, 10:51:04 pm »
[SNIP]

There are limitations. There is no allowance for overriding a decoration used in the base with a new one in the specialized stereotype.

In UML terms, the main script is redefinable. All decorations are added to the collection.
Hi Eve,
I haven't had time yet to take a closer look at this. But, do I understand correctly, that if we have a set of standard decorations that many of our shapescripts use and we put them into a supplemental stereotype, we can use multiple-inheritance to automatically include those decorations in the specialized stereotype?  In your example, rather than A<-B<-C  I have A<-B & C and create B<-D->C  D will execute both sets of shapescripts?

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

qwerty

  • EA Guru
  • *****
  • Posts: 12263
  • Karma: +346/-285
  • I'm no guru at all
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #12 on: February 10, 2021, 12:49:06 am »
I have a stereo «TBD» which just colors an element red via shape script. That had always worked. No inheritance, though. It's plain assignment of multiple stereotypes.

q.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 7921
  • Karma: +205/-127
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #13 on: February 10, 2021, 12:31:12 pm »
I have a stereo «TBD» which just colours an element red via shape script. That had always worked. No inheritance, though. It's the plain assignment of multiple stereotypes.

q.
We've found that we can make all this happen "behind the scenes" with inheritance and supplementals so that we still retain (in the main) the ability to end up with only a single stereotype (the metatype) for the item.  That's why I'm hoping the answer to my question is "yes!".

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 7921
  • Karma: +205/-127
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Inheritance Shape-Script between Stereotyps
« Reply #14 on: February 10, 2021, 10:39:41 pm »
[SNIP]

There are limitations. There is no allowance for overriding a decoration used in the base with a new one in the specialized stereotype.

In UML terms, the main script is redefinable. All decorations are added to the collection.
Hi Eve,
I haven't had time yet to take a closer look at this. But, do I understand correctly, that if we have a set of standard decorations that many of our shapescripts use and we put them into a supplemental stereotype, we can use multiple-inheritance to automatically include those decorations in the specialized stereotype?  In your example, rather than A<-B<-C  I have A<-B & C and create B<-D->C  D will execute both sets of shapescripts?

Paolo
Rather than try to recreate Eve's example in a test profile, I tried to create my example above in our main profile (I could do it pretty easily).  So, as I mentioned we have a bunch of decorations which occur in a large number of our stereotypes.  We currently maintain the shapescript with an external editor which updates the decoration set.

So I exported the set of decorations into a new stereotype StandardItemDecorations and placed them in its _image attribute.  No other attributes were defined.  I then removed them from the main stereotype Item(Generic) and had Item(Generic) inherit from StandardItemDecorations.  As I understand what Eve is saying, this should have worked seamlessly.  It didn't work at all.  :(  The decorations no longer responded to the properties that drive them.  Switching back and forwards between the two versions of Item(Generic) proved this.

Now that I've been using the model-based definitions for a while, I checked the emitted XML and everything looked as I expected.  Am I missing some secret sauce?  For example, do I need a "shape main" in the supplementary stereotype?

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!