Design Format

We provide a set of UML class diagrams for solutions that are coded in Java or C++. These diagrams are a helpful aid to understanding code that takes advantage of class inheritance and polymorphism. Figure 3-3 contains a sample class diagram showing the relationship between a superclass SegmentTreeNode and two subclasses, DefaultSegmentTreeNode and StoredIntervalsNode, that extend SegmentTreeNode using inheritance (as identified by the arrows terminating in triangles). Each class box has two parts: the upper part lists instance variables, and the lower part lists instance methods. The leading symbols for each declared attribute or method are significant:

# (protected)

Declares that the attribute or method is visible to the class or any of its subclasses; if the underlying implementation is Java, then the attribute or method is also visible to classes within the same package. Note that in our C++ implementations, we do not use multiple inheritance or friend classes, so the semantics are nearly identical.

~ (package-private)

Declares that the attribute or method is visible only to classes within the same package; used only by Java designs.

− (private)

Declares that the attribute is visible only to the class itself in which the attribute is defined. We intentionally do not list in the class diagram any private methods that may exist.

+ (public)

Declares that the attribute or method is visible and accessible to anyone. Public attributes are, in general, assumed to be "final" ...

Get Algorithms in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.