Author Topic: How to show calls from derived class to ancestor?  (Read 832 times)

mbc

  • EA User
  • **
  • Posts: 237
  • Karma: +1/-0
  • Embedded software developer
    • View Profile
How to show calls from derived class to ancestor?
« on: July 03, 2003, 10:38:00 am »
How should I illustrate calls from a derived class to the overridden functions of its ancestors?

For example: consider 2 classes CTextButton and CBitmapTextButton where CBitmapTextButton is derived from CTextButton. CTextButton is a button with text, CBitmapTextButton is a button with both text and a bitmap.

When I call the Paint function of CTextButton, it will paint the text on the screen. When I call Paint of CBitmapTextButton it will paint the bitmap on the screen and then call Paint of its ancestor (CTextButton) in order to paint the text.

How can I illustrate this flow in UML? In a sequence or collaboration diagram with classes instead of the usual instances?

Thanks in advance
Mikkel

DMT

  • EA User
  • **
  • Posts: 93
  • Karma: +0/-0
    • View Profile
Re: How to show calls from derived class to ancest
« Reply #1 on: July 06, 2003, 08:04:20 am »
I've found the easiest way to do this is one of two method. I use the first method if there are only a few "base/derived" interactions I want to show. I use the second method if I need to show a lot of intereactions or if the first method just isn't clear enough.

Method 1
1. Create a sequence diagram and drag your derived class onto it
2. Create a message to the derived class (or a self-message, if appropriate), showing an invocation of the Paint() method.
3. Inside the Paint() method, show a message indicating the bitmap will be painted. Depending upon the level of detail you need to illustrate, you could show the actual method calls that accomplish this, or you could just create a "plain text" self-message, something like "Paint bitmap on the button".
4. Again inside the Paint() method, show a self-message with the text something along the lines of "base.Paint()", indicating an invocation of the base Paint() method.

Method 2
1. Drag both the base class and the derived class onto a sequence diagram.
2. Instead of self-messages for the invoked base class methods, show messages going from the derived class to the base class.

Method 2 is a little more "theoretical," since you won't be instanciating two different objects, and probably isn't necessary for your example. I feel that if this method increases understandability, however, the reader can get beyond this small "incorrectness" of the diagram.

I hope this sparks some ideas (no pun intended).

You could certainly use a collaboration diagram to show this as well; I just prefer sequence diagrams because I like seeing time flow from top to bottom.

mbc

  • EA User
  • **
  • Posts: 237
  • Karma: +1/-0
  • Embedded software developer
    • View Profile
Re: How to show calls from derived class to ancest
« Reply #2 on: July 07, 2003, 01:19:08 am »
Thank you very much for your ideas, they are very helpful.
You are right that my example doesn't require a very detailed diagram, but I kept it simple intentionally to make my question understandable. The actual case has a longer chain of derivations, and some classes aggregates other classes, which are themselves derivations.
I have ended up doing something like what you suggest in your Method 2.
Thanks
Mikkel

DMT

  • EA User
  • **
  • Posts: 93
  • Karma: +0/-0
    • View Profile
Re: How to show calls from derived class to ancest
« Reply #3 on: July 07, 2003, 01:12:04 pm »
I'm glad I could help out.

Please forgive the spelling error, by the way.  I have a serious issue with always misspelling "instantiated."