In the last issue (Sun Java Studio 8 Enterprise Edition,
page 59, February 2006), we designed three simple classes for our sample library
management software. To that project, we will now add an interface, add
implementation of the interface to an existing class, and also create a simple
activity diagram using Java Studio.
Creating interfaces
To create an interface, click on the Interface icon from the
'Modeling Palette' and click on the diagram. Right click to switch to the
normal cursor. Rename the Interface by typing the name
'LibraryManagerInterface' and keeping the icon selected. Add the following
operations to the interface.
public boolean
checkStatus(int bookId)
public boolean checkMember(int memberId)
public int computeFine(int noOfDays)
|
The procedure for adding an operation to an interface is
similar to that for a class. Add operations for checkStatus, checkMember and
comptueFine by right-clicking in the Operations section of the Interface and
choosing 'Insert Operation' from the context menu.
Packaging
To model packages, repeat the steps we used for creating interfaces on the
Modeling palette. Rename the package to 'libpack'. To add the classes to
this package, click on the 'Nested Link' icon on the basic section of the
'Modeling Palette'. Click on a class and then on the package. Repeat for all
the classes and interfaces to group them into one package.
Methods from the 'LibraryManagerInterface' automatically appear in the Librarian class after modeling implementation relationship |
Complete UML class diagram for the sample application shows all the relationships between classes |
The workflow process of issuing a book is represented by an activity diagram as shown here |
Relationships
Our interface is implemented by the Librarian class. To model this
relationship, on the Modeling palette select
Implementation>Librarian, and then click on the interface. A new section
appears in the Librarian class titled 'Operations Redefined from
LibraryManagerInterface' listing all the three operations we had created in
our interface. Right click on the Librarian class and click on 'Navigate to
Source Code' from the menu. The Librarian class will open up showing the
changes you had earlier modeled in the UML project. The Library class uses
Member and Book classes as parameters in its methods. This relationship is
represented as dependency in the Studio. To model it, click on the Dependency
icon in the Modeling Palette, click within the Librarian class icon, and then on
Member to model the relationship between the two. Similarly you can model the
relationship between Librarian and Book.
Activity diagram
Activity diagrams essentially help in modeling a business process. Here, we
will model the process for issuing a book. Right click on Model under
'LibraryUML' in the Project Explorer window, and choose Add from the menu
and click on
Diagram in the sub menu that appears. Choose 'Activity Diagram' from
the 'New Wizard' window. Populate name field with 'Issue Book Activity'
and leave namespace to the default value, which will be LibraryUML in this case.
The IDE opens up an empty diagram window with a different
set of icons in the Modeling Palette. Click on the 'Initial Node' icon from
the palette and then click on the empty diagram. The Initial Node represents the
start of an activity (for example, Invocation,
Decision) represent the subsequent steps. Click on the Invocation node and place
it in the diagram, right click and rename the node to 'Request for Book'.
Similarly, draw two more Invocation nodes titled 'Search Book' and 'Issue
Book'. Once 'Search Book'
action completes, we need to check for availability, and then issue it. To model
this flow, click on the Decision node and draw it in the diagram. Rename it to
'Check Availability'. Similarly, draw another Decision node and name it
'Issue Another Book'. To connect the activities, click on 'Activity
Edge', followed by clicking on the Initial node in the diagram, and then by
clicking on 'Request for Book'.
Connect 'Request for Book' to 'Search Book' and
'Search Book to Check Availability'. The 'Check Availability' node then
needs to be connected to 'Issue Another Book' and the 'Issue Book'
nodes, depending on whether the book is available. This draws an activity
edge from 'Check Availability' to 'Issue Book'. To draw another activity
edge from 'Check Availability', from the Properties window and change the
name to Else. Connect the 'Issue Another Book'
Decision node to 'Request for Book'. Click on
'Activity Final' node icon from the palette, place it on the diagram and
connect 'Issue Book' to this node. Finally, connect the 'Issue Another
Book'
Decision node to the 'Activity Final' node and rename
it to Else. This completes our Activity Diagram for 'Issuing Book'.
Modeling can also be done for state transitions, components
and collaboration in an application using the IDE. It is always good to finalize
on these features before you get down to coding to get a well defined platform
on the basis of which all the methods,
interfaces and protocols between objects can be implemented.
Anadi Misra