Visibility notation in UML class diagrams

class-diagramuml

I'm reading about UML class diagrams and notation for visibility, and I can't tell if this book (Learning UML 2.0 by Russ Miles) has a typo or is just not explaining itself.

Consider these two diagrams:

Protected Member:

enter image description here

Private Member:

enter image description here

I fully understand the concept of visibility, as I am a seasoned Java developer.. but I'm curious about the notation here. Is there any significance to the fact that aMethod() does not have a visibility modifier? Why is it in the first picture that it looks as if SpecializedClassInAnotherPackage can access aMethod() from BlogAccount, but the same class cannot access it in the second diagram? The only difference between the two is that the showcased property is protected in the first, and private in the second.

Is this a typo, or am I not understanding something? I cannot readily see anything in the book that would indicate the meaning of having no visibility modifier.

Best Answer

Seems like there is a simple solution to that confusion: the arrows in these diagrams are not accurate as to their destination. They all point to different things when you look at it exactly. Some point to the property with the visibility modifier, some to the other operation, others to the class itself. However, the intention of the author seems to be that each of these is regarding access to the field with the interesting visibility modifier.

Or in short: #creationDate is accessible from the derived class, but -name is not. Granted, the author may have taken more care here as to avoid this confusion.

A little extension on the actual semantics of this. When you take a look at the UML superstructure specification at page 141 you will see the different visibility kinds and their specified semantics. Another post on SO shows you where to look at in the SSS to find out that the default visibility (if nothing is written in front of the operation) is public. (Yes, the SSS is a tough beast to read.. you should learn how to read that document before actually reading it).

Just for the reference, here are the concrete semantics as defined in the UML SSS:

  • A public element is visible to all elements that can access the contents of the namespace that owns it.
  • A private element is only visible inside the namespace that owns it.
  • A protected element is visible to elements that have a generalization relationship to the namespace that owns it.
  • A package element is owned by a namespace that is not a package, and is visible to elements that are in the same package as its owning namespace. Only named elements that are not owned by packages can be marked as having package visibility. Any element marked as having package visibility is visible to all elements within the nearest enclosing package (given that other owning elements have proper visibility). Outside the nearest enclosing package, an element marked as having package visibility is not visible.
Related Topic