The Artima Developer Community
Sponsored Link

Design Forum
UML Notation Question

3 replies on 1 page. Most recent reply: Jun 3, 2004 2:25 AM by Shashank D. Jha

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
David Ramsey

Posts: 34
Nickname: dlramsey
Registered: Apr, 2002

UML Notation Question Posted: Feb 2, 2004 9:26 AM
Reply to this message Reply
Advertisement
Often you attempt to exploit polymorphism to the greatest extent possible and it helps. But sometimes a class ends up with peculiarities unique to that class. So assume I have a Collection c of objects of SomeClass. Further, consider that I want to do a number of operations in sequence on the members of that collection but that I need to do something additional for one special case subclass.

  public void doSomething(Collection c)
  {
    Iterator i = c.iterator();
    while (i.hasNext())
    {
      SomeClass d = (SomeClass) i.next();
      d.doSomething();
      d.doSomethingElse();
      if (d instanceof SomeSubClass)
      {
        ((SomeSubClass) d).doSomethingSpecial();
      }
    }
  }


So above is a contrived example, I am wondering if anyone has any suggestions on the best way to show these messages and interactions in a UML diagram? Nothing really clean hits me though I can see a couple possible ways to diagram it. However, I am thinking this is something others may have had to see and deal with before?


Prasan

Posts: 2
Nickname: psamty10
Registered: Mar, 2004

Re: UML Notation Question Posted: Mar 21, 2004 9:38 AM
Reply to this message Reply
IMHO... modelling something at the functional level is neither necessary nor practical. UML is not code, so it doesnt have to exactly match what the function represents, just give a general idea of what it does.

The reason nothing clean hits you to diagram it is because ideally youd be using virtual functions (the default in java). If the classes in the collection all derive from the same ABC, adding a virtual function to execute that exact sequence would make the code look cleaner, and would also solve your UML modelling problem.

And if you really want to exploit polymorphism to the greatest extent, thats exactly what you should do...

Shashank D. Jha

Posts: 68
Nickname: shashankd
Registered: May, 2004

Re: UML Notation Question Posted: May 5, 2004 9:04 AM
Reply to this message Reply
Your situation (I mean code necessity) shows where quite often developers are stuck, they resort to these tricks.

But if analyzed at higher abstraction level, these can be avoided by proper design.

As currently pointed at, representing this in the UML is not the aim nor any obvious ways, but sure it can avoided by doing better analysis at UML design level.

But yeah deep down somehere programmer may opt for this.

Shashank D. Jha

Posts: 68
Nickname: shashankd
Registered: May, 2004

Re: UML Notation Question Posted: Jun 3, 2004 2:25 AM
Reply to this message Reply
You may use patterns like Visitor, Bridge, IntelligentChild, RTTIVisitor etc to avoid explicit downcasting and protect your software from uninteded crash.

regards,
Shashank

Flat View: This topic has 3 replies on 1 page
Topic: Practically OOPs Previous Topic   Next Topic Topic: UML Design: Whether required?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use