You are on page 1of 12

Getting started

1. Launch StarUML. The following window will appear.

2. Select Rational Approach. Click OK.

3. Take note of the Model Explorer which consists of the Use Case View, Logical View,
Component View and Deployment View.
4. Rename the project to MyLibrary.

1
5. Since in this tutorial we would like to show how java code can be generated from the classes,
we will add the Java Profile into the project.
6. To add the Java Profile to the project, click on Model Profile

7. Select Java Profile and click Include

8. The Java Profile will be included in the project

2
Creating a Use Case Diagram

1. Double click on the Use Case View. You may start drawing your Use Case in the default ‘Main’
diagram.

Notice the diagram notations on the Toolbox on the left pane. The content of the Toolbox
changes depending on the type of diagram that is currently being drawn.

2. To draw the Use Case make sure you are in the Main diagram of the Use Case View.

3
3. Start by adding an actor to the diagram. Click on an actor, click anywhere on the diagram, and
name it as Librarian.

Notice that the Librarian actor is added to the Model Explorer under the Use Case view.

4. Next, add a use case Register Book. Again notice that the use case is added to the Model
Explorer.
5. Use the association notation to link the actor to the use case
6. Complete the whole use case as follows:

4
Creating a Class Diagram

1. Double click on the Logical View. You may start drawing your Class diagram in the default
‘Main’ diagram.
2. To draw the Class diagram make sure you are in the Main diagram of the Logical View.

3. Start by adding a class to the diagram. Click on a class, click anywhere on the diagram, and
name it as Book.

Notice that the Book class is added to the Model Explorer under the Logical view.

4. Next is to add the attributes of the Book class.

5
5. Double click on Book class and click on the blue rectangle.

6. Replace Attribute1 with title. Notice that the Model Explorer now shows the Class Book and
the attribute title.

7. Add another attribute author by clicking on the ‘+’ sign.


8. To add an operation, double click on Book class and click on the red rectangle.

9. Complete the attributes and operations until you get the following class:

10. Notice the ‘+’ signs in front of the attributes and operations. This sign means that the
attributes and operations are public. Remember that a class attributes are usually private and
class operations are usually public. Therefore we need to change the class attributes’ visibility
from public to private.

6
11. Double click on attribute title and click on the visibility icon on the left hand side.

12. Choose private. The sign in front of the title attribute is now changed from ‘+’ to ‘-’.

13. Do the same for the other attributes.


14. Create another class Borrower with the following attributes and operations:

15. In a class diagram, we can even set the data type of each attributes. Let us set the datatype for
the attributes of class Book and Borrower.
16. Class Borrower has attributes id, name and maximumBook. Id is of type String, name is of type
String and maximumBook is of type integer.

7
17. In the Model Explorer, select the class Borrower and click on the id attribute

18. In the Properties, click on the type for the id attribute

8
19. Click on the icon. The following window will appear:

20. Click on the drop down arrow of Data Type and select Java String

21. The attribute id of class Borrower will now have the type String

9
22. Do the same for id name and maximumBook
23. Repeat the same for the attributes of class Book.
24. Class Book has attributes title, author and borrower. title is of type String and author is of type
String.
25. However, this time, the attribute borrower’s data type is actually a type of class Borrower.
26. Therefore, to set the data type of borrower, you need to perform the same step as before,
however, instead of selecting the data type from the drop down list, click on MyLibrary
Logical View Borrower.

27. Click OK. The attribute borrower will be of type class Borrower. Now the class Book will look
like this:

10
Generating code (skeleton code)

1. To generate code from your class diagram, simply do the following:


2. Click on Tools Java Generate Code ...

3. Select Logical View package. Remember, this is where your class diagram is stored. Click Next.

4. Click Next again. (Since you want to generate code for both classes)

5. Select a place to store your generated source code.

11
6. Click Next. (Leave the default preference)

7. Java code should be generated successfully

8. Go to the folder where you have chosen to store your generated code. There should be two
java files created.
9. Open the java files with any editor and look at the codes generated by StarUML.

12

You might also like