CPSC 329 Software Development Fall 2017

CPSC 329 Lab 5: Papyrus

Papyrus is a free plugin for Eclipse which allows the creation of a number of types of diagrams. We will be using it for class diagrams because, while it is a bit more cumbersome than PlantUML to use, it is capable of generating Java class skeletons from the class diagram.

Objectives

Successful completion of this lab means that you:

Collaboration

Work in pairs (and one group of three) to complete this lab. Other than the code generator installation, only one person needs to carry out the steps in the lab but everyone in the group should make sure they understand what is going on. There is no limit on collaboration with others, but you need to make sure that you understand for yourself how (and why) to do things.

Due Date and Deliverables

due Tue Oct 3 at the start of class

One handin per group.

To hand in the lab, create a handin tag as directed and include the names of everyone in your group in the commit comment.


Setup

It is assumed that you have the Papyrus plugin installed in Eclipse - lab 1 contains the instructions if you need to install it.

You will also need to install the code generator: (everyone in the group should do this)

Create a project for this lab: (only one person should do this)

There isn't anything special about the name of this folder; it just is a way to organize the various files within the project.

Only one person in the group needs to carry out the steps in the rest of this lab.


Class Diagrams

Creating a Model

The first step in creating a class diagram is to create a model:

The result should be the creation of three files lab5.di, lab5.notation, and lab5.uml in the classdiagram directory.

Finally, open the editor:

Creating the Class Diagram

Use the Palette tab on the right side of the editor window to select the type of component to create, then click in the editor window to create an instance of the desired component.

Use the Properties tab below the editor window to edit properties of the currently-selected component (if any).

Information on specific components can be found in the sections below.

Classes

Classes are created using the "Class" item in the Nodes section of the Palette. Edit the class name by typing the desired name immediately after creating the class (the class name should be editable) or by selecting the class, going to the UML tab within the Properties view, and entering the desired name in the Name box.

Properties

Properties are used for instance variables. Note: if the type of the variable is a class type, create that class first.

Add a property to a class by selecting and then mousing over the desired class, then choosing the 7th icon from the left (mousing over the icon should show "Add Property Class Attribute Label"). A new property is created with some placeholder text. Edit the placeholder text by clicking on the desired property twice (note that this is two separate clicks, not a double-click) and typing the new contents or by clicking on the desired property once (to select it) and then going to the UML tab within the Properties view. (Use the Properties view unless you are sure of the format to type directly.) In the Properties editor, fill in the "Name", "Visibility" (private), "Multiplicity" (1 for a single value with null not an option, 0..1 for a single value with null as an option, 0..* for a possibly empty collection, and 1..* for a non-empty collection), and "Type" boxes (click on the ... icon to choose). Browse through the available options to choose the appropriate type; if the desired type isn't listed, cancel out and create a class for that type first.

Operations

Operations correspond to methods. Note: if the type of any of the method's parameters or return value is a class type, create that class first.

Add an operation by selecting and then mousing over the desired class, then choosing the 5th icon from the left (mousing over the icon should show "Add Operation Class Operation Label"). A new operation is created with some placeholder text for the name of the operation. Type in the name (and just the name, without any visibility modifiers, parameters, return values, or even parens).

To edit the name later or to set/change any of the other properties, click on the desired operation to select it, then go to the UML tab within the Properties view below the editor view. Fill in the "Name" and "Visibility" values. For parameters and the return value (if any), click on the + button for "Owned parameter". Fill in the "Name", "Direction" ("in" for parameters, "return" for return values), "Type" (click on the ... icon to choose), and "Multiplicity" (1 for a single value with null not an option, 0..1 for a single value with null as an option, 0..* for a possibly empty collection, and 1..* for a non-empty collection) boxes. Browse through the available options to choose the appropriate type; if the desired type isn't listed, cancel out and create a class for that type first.

Aggregation and Composition

To show aggregation and composition relationships between classes, choose either "Shared Association (Directed)" or "Composite Assocation (Directed)", respectively. (Find these under "Association (Directed)" in the Edges section of the Palette.) In the editor view, click first on the "whole" class and second on the "part" class to create the association line. Once created, verify that the diamond icon appears on the "whole" class end, then click on the line to select it and go to the UML tab within the Properties view below the editor view. On the Member End associated with the "part" class, change the Owner to "Assocation" (this will make the arrowhead on the line go away) and update "Multiplicity" as needed (1 for a single value with null not an option, 0..1 for a single value with null as an option, 0..* for a possibly empty collection, and 1..* for a non-empty collection).

You can drag the ends of the line around as needed to clean up the diagram.

Association

For a plain association (an association other than aggregation or composition), use the "Association (Directed)" element. In the editor view, click first on the referencing class and second on the referenced class to create the association line; verify that the line points in the correct direction (in the direction of the reference). To edit multiplicity, click on the line to select it, and go to the UML tab within the Properties view below the editor view.

Layout

There is an auto-layout feature - right-click on the background in the editor view and choose Arrange All.


Specifications

Specifications are entered by clicking on the element in question (class, property, or operation) so that it is selected, going to the Comments tab in the Properties view below the editor view, and adding an Owned comment. (Enter the comment in the "Body" box in the "Create a new Comment" dialog.) For parameter and return value descriptions, select the parameter/return value in the "Owned parameter" section of the operation's properties, click on the edit icon, then add an Owned comment on the Comments tab of the "Edit Parameter" dialog box that appears.


Generating Code

Generate skeleton code by right-clicking in the background of the editor view and choosing Designer->Generate java code. You will be prompted about creating a new project; say "Yes". Accept the defaults in the new project wizard.


Handin


Valid HTML 4.01!