A Tutorial on How to Use Together
Sandhya Gupta


This tutorial aids in building a simple project from scratch. We look at a simple problem of keeping track of flight reservations and ticket revenue of a regional airline.

To create a new project (name: Airlines)

Open Together and select File|New Project from the Main menu. A New Project dialog box like the one below appears.

By default, Together creates a new directory for the new project inside $TOGETHER_HOME$/myprojects. The name of the directory is the same as the project name. Together gives a choice of three languages: Java, C++, or CORBA IDL.

At a minimum, a project consists of:



Working with the <default> diagram

A <default> diagram is created for each new project. It shows primary root directory packages as well as classes of any source code files in that directory. (Default diagrams and diagrams for packages are class diagrams.)

When a project is first created, the <default> diagram is simply a blank background. Below are two views of the newly created project in the Explorer pane.
 
 This is directory tab view. The primary root directory (airline) contains no other directories when the project is first created. 
(.tpr indicates a project file). 
This is Model tab view. There is only one part of the model. It contains no elements at the start.


Creating new packages

The <default> diagram is the place to start organizing a project into packages. The airline project will have three packages.

Create a new package named ProblemDomain inside the <default> diagram.
 

To create a new package, click on the package button ()of the vertical Diagram toolbar. Then click on the diagram background. The diagram will get a new node. 
At this point, you can edit the package name by typing directly in the in-place editor that is now active. Press Enter to apply the name.

Note: Together automatically creates a physical directory for the package and generates a default diagram inside the directory.
 
The <default> diagram contains a single node which is a package.
The Model tab of the Explorer pane shows the new Package node. Inside the new package is a node for another diagram, which has the same name as the package. Both the new package and the new diagram are currently empty.
The Directory tab of the Explorer shows the new file structure of the project. 
There's a new subdirectory of the primary root directory named ProblemDomain. That directory now contains the file ProblemDomain.dfPackage, which is the default diagram for the new package. (.wmf file is Windows metafile.)


Create two additional packages in the <default> diagram: UserInterface and DataManagement

Shortcut for creating multiple packages - Ctrl+Click the package button on the toolbar to keep the button depressed. While the button is depressed, click on the Diagram pane and create packages.

To release the button, click it again. (If an extra package is dropped on the diagram by mistake, the undo button on the Main toolbar will remove it.)


Showing package dependencies

Create a dependency from UserInterface to ProblemDomain.
 
The Diagram pane toolbar provides an entire suite of tools for creating UML model elements.
1)  To create a package dependency, click the dependency button (  ). 
2)  Click the dependent package (the "client") in the diagram and drag the end of the arrow to the package that it depends on (the "supplier").

An example is shown here. 
 


Various aspects of the airline problem are -

Use Case diagrams are used to capture these requirements.

Creating a new diagram

Open the airline project created in the previous part. Bring the ProblemDomain diagram into focus (bring it to the front in the Diagram pane).
Create a new Use Case diagram named MakeReservation.
Clicking the New Diagram button () on the Main toolbar brings up a New Diagram dialog box.
On clicking OK, the new diagram shows up in the Model and Directory tabs of the Explorer pane.


Creating actors, use cases, and a system boundary

MakeReservation diagram should be in focus in the Diagram pane.
Create three actors: Passenger, FinanceOfficer, and Agent.
The Diagram pane toolbar varies according to the type of diagram. Click the actor button () and then the diagram to create a new actor and fill in the actor's name.

Put a system boundary on the diagram and name it Airline Reservation System. To proceed:
 
  • Click the system boundary button (
  • Click the diagram to create the system boundary
  • Fill in its name with the in-place editor. 

Create four new use cases:

by following the steps:
 
  • Click the use case button (
  • Click on the diagram to create a new use case
  • Use the in-place editor to fill in a text description. 


Connecting diagram elements

Communication links indicate which actors are involved in which use cases. The diagram will involve the Agent in three use cases but the Passenger will participate in only two and the Finance Officer in only one.

Create some communication links:

 The same technique is used to create any linking element (communication, dependency, association, etc.). A link is created using communicates button on the Diagram toolbar ().
 
A thin shadow appears around elements as cursor is passed over them.  Click the source element in the Diagram pane.
Drag the end to the target element. 

An actor can be a target or a source for a communication link (but not both!).

Connect the use cases:

 The Diagram toolbar has an extends button () and an include button (). The choice of target vs. source choice is important for these links. For example, when  use extends, Buy a Ticket is the source and Make a Reservation is the target.

Diagram after completion



----------------------------------
In this section, details of what it means to "Make a reservation" is listed in the context of activity diagrams.
The question to ask is : How can we "Make a reservation?"
Answer: A flight reservation is made only if the number of tickets sold for the flight does not exceed the capacity of the airplane.

Create a new Activity diagram in the ProblemDomain package and name it Request Reservation.
 
Click on New diagram icon () on the main toolbar.
Enter the name in the textfield.
Together uses the description and generates documentation.

If you check "include in current diagram", the ProblemDomain package diagram should show a shortcut to the activity diagram.


 

Following activity diagram toolbar buttons are shown:
 
Swimlane Transition
Start Horizontal Fork
Stop Vertical Fork
Activity Decision


Organizing activities, start and stop states with swimlanes

Making a request is divided into three pieces.

Swimlanes are often not associated with classes or objects.

Make three swimlanes in the diagram.

To create a swimlane, click the swimlane button () on the Diagram toolbar & then click the diagram.
To change a swimlane name, click on the name to bring editor.

 Resulting diagram

Put a start state at the top of the activity diagram (above the swimlanes) and put a stop state below the swimlanes.


Creating activities and transitions

The initial activity for the activity diagram is receiving a reservation request.

Create an activity named Receive request and put it inside the Flight Reservations swimlane. Link the start to the activity with a transition.
 
Creating activities on activity diagrams is analogous to creating use cases on use case diagrams. Start with the activity button on the toolbar (). 

Activity diagram transitions are analogous to use case diagram communications. Click the toolbar transition button (), & Together highlights sources and targets for the transition as cursor is passed over them.

Snapshot shows making transition from start point to the activity.

Create five more activities:

Once an activity is created, drag it to any swimlane (or even outside swimlanes entirely).



Changing flow of control with forks, joins, and decisions

Before the airline can make a reservation, it checks to see if the flight has room. Get capacity and Get #tickets can be performed in either order. But they both have to be completed before the remaining activities can begin.

Create a fork. Make a transition from Receive request to the fork. Then make transitions from the fork to Get capacity and to Get #tickets.
 
The fork buttons on the diagram toolbar gives a choice of horizontal forks () or vertical forks (). The choice depends only on how you want the diagram to look.
A fork can be a source or a target of a transition ().

Be sure to look for the highlight when a transition is drawn to a fork. Forks are so slim that it is easy to miss a target fork and land on a swimlane instead. If we end a transition on a diagram entity, it is not a valid target. Together writes a red error message in the Message pane, and it displays an error box.

Create a join. Then make transitions from the Get capacity and to Get #tickets to the join.
The join button is the same as the fork button either horizontal or vertical.

Make a decision node to compare the number of tickets to the capacity of the airplane. Make a transition from the join to the decision. Then make a transition from the decision to Create reservation and another transition to Refuse request.



Create a join. Make transitions from the Get capacity and to Get #tickets to the join.
Join button is the same as the fork button.
Make a decision node to compare the number of tickets to the capacity of the airplane. Make a transition from the join to the decision. Then make a transition from the decision to Create reservation and another transition to Refuse request.
 
The decision button is the diamond () on the diagram toolbar. To get the snapshot on the left, we set our Diagram Options to show rectilinear links. The options can be set from the Main menu under Options|Diagram.

Label the decision with guard conditions to indicate which transition applies.

Put guard conditions on the transitions out of the decision:

Transitions have inspectors that one can access from their speedmenus. Right click on the transition line and you'll get the properties inspector at the right.

The link properties inspector has a Link tab with a textfield for the guard condition. The Req tab has a textfield for business rules. The Description tab has a textbox for descriptions.

Put in a second decision. Make four transitions:

Guard conditions appear on the diagram in square brackets. You can change a diagram by dragging guard conditions or activities.

Completed activity diagram is shown below:



 In this section, we'll see how to work on the problem domain package by creating classes.

Creating new classes

Here are the initial requirements of the airline project.

From these requirements, five problem domain classes can be made. Some possible attributes and operations of these domain classes are listed.
 
 
Class  FlightDescription  ScheduledFlight  Reservation  Ticket  Agent
Attributes departureTime
arrivalTime
origin
destination
capacity
date name basePrice name
Methods getCapacity()
setCapacity()
makeReservation()
numberOfTickets()
ticketPurchased()
calcPrice()
calcPrice() makeReservation()

Begin by bringing the ProblemDomain package into focus in the Diagram pane.

Create five classes in the ProblemDomain package: FlightDescription, ScheduledFlight, Reservation, Ticket, and Agent.
Ctrl+click the class button on the Diagram toolbar () to create multiple classes.
 
As classes are created in the Diagram pane, the Editor pane displays the new code. 
Below is a picture of the ProblemDomain package node. The + beside each name indicates that the class is public.

Together has now generated source files for the classes in the physical directory of the package. The Explore Model tab tracks the new classes as part of the current project.



Adding attributes

It is often quickest to add members to a class through its Diagram pane node.

Go to the Diagram pane to add a name (type String) to Reservation.

To add a new attribute to a class, select the class in the Diagram pane and choose New|Attribute from the class speedmenu. (keyboard shortcut, Ctrl+A.)
 
The new member gets a default name (attribute), type (int), and visibility (private). All these can be changed by in-place editing on the diagram node. 

Together keeps diagram and code in sync, automatically adding the declaration to the source code. 
Snapshot shows results in Editor pane.

There are several ways to add attributes to a class through the Diagram pane.

One can drag-and-drop attributes within a class to reorder them.

Edit three properties of the name attribute of the Reservation class.

Put additional attributes in the five AirlinePD classes. Use the Diagram pane rather than the editor to enter the new attributes.

Changing class properties

Change the Ticket class:

Make a class abstract by using its speedmenu or its property inspector. Check the Abstract box on. Use the same procedure to make a method abstract.


Creating associations

Open the AirlinePD package diagram in the Diagram pane.

Create an association from Flight to FlightDescription.
 
Begin by clicking the association button () on the Diagram toolbar. Associations are handled the same way as linking elements in other diagrams. As you pass the cursor over valid client (start) and supplier (end) nodes, Together puts a highlight around them. 
Drag the cursor from Flight to FlightDescription and release. The Diagram pane will show the new association as a blue line.

If you look in the Editor after creating the association, you'll see that Flight has member named lnkFlightDescription
 

Create two more associations:

Together gives a choice of link display:  rectilinear or direct.
Link displays are set on the diagram options, accessible via Options|Diagram on the Main menu.

Most links go from one class to another but some can be self-links, starting and ending at the same class. You can put a self-link in our model to distinguish between a flight plan and an actual flight.

Make the diagram link display to be Direct. Then draw a self-link on Flight.

Snapshot of the diagram



Modifying associations

Association links are Together objects with their own speedmenus and inspectors. For many modifications, you can use either speedmenu or inspector.

Put cardinalities on the link from Flight to FlightDescription.

The link speedmenu varies according to which end is closer to the cursor. To target the end of a link in order to assign it a cardinality or a role, right-click on the link near that end.

The speedmenu lists the most commonly seen cardinalities. 

Assign appropriate cardinalities to the link connecting Reservation and Ticket using this rule:
A ticket must be associated with exactly one reservation, but some reservations may not have any tickets.

Assign cardinalities on the link from Agent to Flight using this rule:
An agent may know about many flights; a flight may be known by many agents.
 
Make the link directed.

Assign a role and 0..1 cardinalities to each end of the self link on Flight and make it directed. Then name the ends:



Changing a link to an aggregation

Every Flight has a collection of Reservations rather than just a single Reservation.
Make an aggregation from Flight to Reservation.
 
 Create the association, starting at Flight and ending at Reservation. Then bring up the speedmenu of the new association and check the Aggregation box.

The link should now show with a diamond at the Flight end.

When you select a link, the cursor changes to a crosshair (). Moving the cross reshapes the link. If you move the cursor to an end of the link, the cursor changes shape to a 4-ended arrow(). At this point, you can move the endpoint of the link to a different class.



Showing inheritance relationships

We will now extend two concrete classes from Ticket (an abstract class).

Create a class named Coach. Then complete these steps.

Use the Generalization link button () to make Coach extend Ticket.


Adding notes to diagrams

You're almost finished with a first crack at the airline project. But put in one more item before going on, a note to explain the business rule for making a reservation:

"You can make a new reservation on a flight if the number of tickets already sold is less than the flight capacity."
Put a note on the AirlinePD class diagram to show this business rule. Then set the note type to business rule.
 
Use the note button () on the Diagram pane toolbar -- enter the text directly in the note node on the diagram. When you're finished, link the note to the Flight class via the note link button (). 

You can set the type of the note on the Req tab of the Properties inspector of the note, as shown here on the right.

Snapshot of AirlinePD class diagram after we created the note. The links are rectilinear. The layout inheritance is horizontal.
 


Creating a sequence diagram

Bring the AirlinePD diagram into focus. The first sequence diagram will be for activity in the problem domain.

From the AirlinePD package, create a sequence diagram named FindRevenue.
To create a new diagram, click the left most button on the Main toolbar (). Snapshot of new diagram dialog with diagram description as well as name.

The sequence diagram toolbar has five items of interest:
 
 
An actor can start the message chain
An object receives and sends messages
 A message  link between objects
A self message  call to a method on the same object
A statement block  for control statements (loops, etc.)

Place an actor on the left side of the sequence diagram. Then put in three objects.
Together draws a dotted lifeline below each object except the actor, which has a narrow rectangle instead.
Create a message from the actor to the Object2 lifeline.
 
Drag a message from one lifeline to another. The action is similar to dragging an association from one object to another on a class diagram and dragging a transition for activity diagrams. 
When you finish, the target lifeline will have an activation bar (rectangle) starting at the point of the arrow. (An activation bar can be lengthened, shortened, and moved along the lifeline.)
Together highlights the valid source and target lifelines as you pass the cursor over them.

Create a message from the activation bar on Object2 to the Object3 lifeline.
 
Our sequence diagram snapshot shows strictly generic classes and messages, completely unrelated to classes or operations in the class diagram.



Introduction to UML