Class diagrams are the most common type of diagram in most object models. They show the static structure of the system, in particular, the things that exist (such as classes and types) and their internal structure. Class diagrams also depict collaborations and relationships between classes, and inheritance structures. A Class diagram may also show instances (or objects) and links between objects,
Class diagrams define a vocabulary for the system, and may also be the basis for Component and Deployment diagrams.
Class diagrams are the basis for visualization, specification, and documentation of the structure of the system and also for the implementation: it is Class diagrams that are round-trip engineered by Together.
Class diagrams that show only Packages are referred to as Package diagrams.
If you need to learn how to create new diagrams in a project, or the techniques for placing elements and drawing links, consult the User's Guide topics found under " Working with Diagrams: Basic Diagram Techniques" in the Table of Contents. See Related Topics below.
Class diagrams usually contain:
Classes
Interfaces
Relationship links, specifically:
- Dependencies
- Generalizations
- Associations
Elements of Class diagrams are defined by the UML and Together provides these on the Class Diagram Toolbar. Use Tool-tips to identify the different elements on the toolbar.
Class diagrams may also contain Packages. These represent underlying physical packages that are part of your project, subsystems of a larger system, or logical groupings of information from any resource available to your project. Since Together diagrams can contain any kind of elements, diagrams can also be used as general grouping mechanism for creating different views. A diagram that is imported into another diagram is shown as a Package with a corresponding stereotype-icon. For more information, see Creating Views.
Outside of the basic mechanics of drawing the diagram to construct your model, there are several conceptual things you should understand about Class diagrams:
How to show classes from packages that are
part of your project
How to show classes
from search path packages outside your project
Packages, classes and (Java) interfaces that belong to your project display in the Model tab of the Explorer. These are defined in your project properties (File | Project Properties). If you specified a Class diagram as the default diagram when you created the project, the project package contains a Class diagram that maps out the packages that belong to the project. Depending on your specifications in the New Project dialog (and later Project Properties), the classes of these packages may be reverse-engineered into Class diagrams.
Assuming this is the case, the Class diagram having the same name as its containing package shows the classes and interfaces in the package, along with relationships and dependencies. You can optionally add classes from any package in the project in these diagrams, or you may choose to create new Class diagrams in a package to show different views of the package contents and relationships to other packages. For example, you might create different Class diagrams to show classes for components or subsystems contained in multiple packages. Assume for the moment that everything in such views resides in a package that belongs to the project and thus displays in the Model tab.
To show classes etc. from another project package in a Class diagram:
In the Model tab, navigate to the package containing the element(s) you want to show.
Select the desired element in the Explore and copy it to the Clipboard.
Paste the element in the desired location in the diagram.
After copying all elements, choose Update Package Dependencies from the diagram speedmenu.
When you create a project you can define directories any number of search paths whose content you may want to show in diagrams. For example, you might want to show things that reside on the standard for full Java classpath. Such resources "exist" for the project but are not included in generated HTML documentation as belonging to the project.
To show classes etc. from one of the search paths in a Class diagram:
Open or create a Class diagram.
Right-click on the background and choose Add Shortcut from the speedmenu to launch the Add Shortcut dialog. This dialog shows all the content available for the diagram on the left-hand side, and all content residing outside the current package on the right.
Navigate to the resource you want to add and click the Add button. Repeat until you have added all the resources you want.
Click OK to close the dialog.
Tip: If the resource you are looking for is not shown, it is probably not in the search paths defined in Project Properties. You can add resources to the search paths at any time by choosing File | Project Properties | Advanced and selecting the tab for search paths. For more information, see User's Guide: Creating and opening a project- Advanced mode.
The easiest way to create an inner class is to drag it over another class and drop it. This works well when the inner class already exists. If the inner class doesn't exist you can create it and define it within its parent at the same time.
To create and define a new inner class:
Select the parent class.
Choose New | Inner Class from the speedmenu.
Tips:
You can also
define new inner classes from the speedmenus of classes in the Explorer.
You can use drag-drop to remove inner classes from classes in the diagram.
You can import another diagram of any type into a class diagram creating an automatic link to that diagram. A diagram that is imported into another diagram is shown as a Package with a corresponding stereotype-icon. You can open the diagram from the context menu of the package icon. (See also: Packages below).
A class is the descriptor for a set of objects that have the same attributes, operations, relationships, and semantics. Classes usually implement one or more interfaces. Classes capture the vocabulary of the system.
In Together, classes have various properties in addition to the usual members. Most of these are defined by the UML, but some such as alias are provided as enhancements to communication. Some properties of interest are listed below:
|
Property |
Description |
|
Name |
Every class has a name to distinguish it from other classes. Name is a text string. You need only enter the simple name for classes (as opposed to qualified name). Because classes are coupled to round-trip engineering, name must be a valid identifier for the target language. |
|
Stereotype |
Provides problem-specific extension of the basic UML vocabulary for a class. You can enter a new stereotype in the property Inspector (Speedmenu | Properties) as you model, or choose from a list of the stereotypes defined in your configuration. |
|
Alias |
Optional alias replaces the Name in the diagram. Because spaces and other characters aren't allowed as class names by e.g., Java, using aliases can make your class diagrams more readable. |
An interface is a device that unrelated objects use to interact with one another. It defines a set of methods but does not implement them. A class that implements the interface agrees to implement all of the methods defined in the interface. Interfaces are only supported in Together products with Java language support.
Interfaces have the same properties as classes except for Implements.
An Object represents an instance of a class. Objects are displayed on diagrams to facilitate communication about the model; they have no representation in source code.
|
Property |
Description |
|
Name |
Name is any text string since Objects are not coupled to round-trip engineering. |
|
Stereotype |
You can assign Actor or Database as stereotype or enter any stereotype name you want. |
|
Persistence |
You can choose transient, static, or persistent or enter any stereotype name you want. |
There are several standard relationships defined by the UML and applicable in class diagrams. Together's class diagrams support:
Association: a structural relationship describing a set of object links. There are two specialized forms of Association:
Generalization: denotes a relationship in which objects of a specialized element can be substituted for the objects of a more general (parent) element.
Implementation: visually the same as Generalization and drawn with the same toolbar icon. Use to show the inheritance of the implementation of a more specific element
Dependency: indicates a semantic relationship between two (or more) model elements in which a change to the independent element may affect the dependent element.
For tips on drawing Associations, see Tips and Tricks above.
A Package is a group of items of the physical model. Packages may also show logical groupings of model content.
Packages often represent physical directories. If the default diagram for the project (specified in your configuration) is a Class diagram, it will contain Package icons for each physical subpackage under the project directory... essentially it is a Package diagram.
Other diagrams of any type may be represented in a class diagram.
These appear as Packages with a visual stereotype, i.e., the icon
representing the diagram type. Packages are represented in the
Explorer, Diagram toolbar, and element selectors in dialogs with a
smaller icon of the same shape:
![]()
TIPS:
Viewing Packages and content: The Model tab of the Explorer displays the packages and subpackages in the project. You can use the Explorer to navigate into them and view their contents.
Opening packages: Choose one of the Open commands on the speedmenu.
Renaming a Package: You can rename a package in place, or using the properties Inspector (Speedmenu | Properties). This change is propagated to all the source files.
Moving elements into Packages: Classes and interfaces can be visually moved to other packages by dragging from the diagram to the target package. For more information see Manipulating elements. Other packages, imported or compiled classes or interfaces cannot be moved in this way however. Pressing the CTRL key and dragging a class into a package imports the class into that package. The class name in italic appears in the package icon.
By default the package icon on the diagram displays its updated contents. You can use the class/interface context menu and add attributes and operations directly. The diagram option Subpackages controls how the packages are displayed in the diagram.
Moving nodes from Packages: You can move that class or interface to the current diagram, deleting it from its current package and moving it to its new package by dragging the class or interface name from the package element to the diagram background.
Dependency links: When you choose Update Package Links on the diagram speedmenu, Together scans each package on the diagram. If it finds an element within the package that is linked to an element of another package, then it creates a Dependency link between those package icons on the diagram.
This covers only source-code based elements. Inter-package dependencies between such elements as Objects, Notes, search-path imported classes, Use Cases, etc. are not recognized.
Deleting a Package: You can only delete a package using its context menu if all of its contents have been removed first.
Note: A physical package can't be deleted if it contains source or diagram files, files of non-Together types, or if other applications share the corresponding directory.
To add a member to a class or interface:
Right-click on the class or interface
Select New | Attribute or New | Operation
The member is inserted after the last attribute or operation, respectively
If a class or interface already has attributes or operations, you can right-click on these directly to create the additional member using the existing member's speedmenu. The new member is inserted before the selected member.
You can also add members form the Explorer. Use the speedmenu of class or interface nodes.
To edit a member name in place:
Click the member once to select it,
Click it again to activate its in-place edit field.
Press ENTER when finished editing.
Note: You can enter only the name (as you would in the Name property in the properties Inspector) or you can enter the full declaration for the attribute or operation. Use full correct syntax for the target language of the class.
See also: Editing properties
Use drag and drop to reorder members within a class icon. The members are reordered in source code simultaneously.
Dropping one member on another member name positions the dropped member before the target member. Dropping a member on the class name moves it to the last position in the attribute or operation list respectively.
Use the Association icon
on the toolbar to draw all types of Association links. After drawing
the Association link, select it and use the link's
speedmenu to specify which type of association to show in
the diagram. (You can also change the type by applying the
appropriate pattern to the link.)
Tip: You can show the direction of Associations by setting the Directed property in the link's properties Inspector (Speedmenu | Properties). For more information see User's Guide: Common Customizations: Association direction.
|
|
|
How to show different Association types. The directional arrow is specified in Default or Diagram Options. |
Java Beans, including Enterprise JavaBeans (EJB), are displayed as classes with two additional sections, one for properties, and the other for events to which the Java Bean can respond. When you select, the Beans support option all the classes on the diagram are rescanned. Those classes with get and set methods are displayed as Java Bean nodes on the diagram denoted by a Bean symbol by the class name. Display support for Beans is controlled in Default and Diagram Options.
To enable display of Java Beans-specific information:
Invoke the Options dialog at default, or project level (see Getting
Started Guide: Using the
Options dialog, and Multi-level
configuration architecture).
Select the View Management tab in the Options dialog
Check the option Show
Beans. Optionally
check the Show Accessors
option if you want to show the access methods in the Bean class icon.
Click Apply or OK.
Tip: You can create new Bean and EJB classes using Class by Pattern on the diagram toolbar.
Non-trivial systems will probably require many class diagrams to capture the static structures of a system. Use the Clone feature to create new diagrams with identical content in the same package (diagram speedmenu | Clone) or new elements with identical properties in the same diagram (element speedmenu | Clone).
You can find detailed information on UML modeling techniques for Class and Package diagrams in Chapters 8-12 of the UML User's Guide.
You can find detailed information about component modeling in color in Java Modeling in Color with UML: Enterprise Components and Process.