SDE for Eclipse UML CASE Tool Tutorial - Full Software Development Support in Eclipse UML Tool |
Chapter 2 Full Software Development Support
SDE for Eclipse/IBM WebSphere Studio Application Developer® allows you to perform system analysis, design, implementation and round-trip code engineering all within the Eclipse/WSAD® environment.
In this chapter:
Performing Analysis
Performing Design
Performing Implementation
Round-trip Support
1. Start Eclipse/IBM WSAD®, then select the File menu > New > Project... to create a new project.
2. When the New Project dialog box appears, select Java and then click Next > to continue.
3. In the next step, enter "School" in Project name, deselect Use default and enter "C:\ECProjects\School" in Directory. After that, click Finish to create the project.
4. When asked to switch to the Java perspective, click Yes to confirm.
5. Click on the New Use Case Diagram button on the toolbar to create a new use case diagram.
6. Create a system and name it "Enrollment System".
7. Create an actor and name it "Student".
8. Create a use case "Enroll into a course" from the actor "Student" using resource-centric.
9. Create another actor and name it "Course leader". Like the actor "Student", it will be placed outside the system.
10. Create a use case "Maintain courses" from the actor "Course leader" using resource-centric.
11. Let's elaborate the use case "Enroll into a course" using textual analysis. Right-click on the use case "Enroll into a course" and select Sub Diagrams > Textual Analysis > Create Textual Analysis from the popup menu.
12. Enter the following problem statement into the problem statement editor:
A student can enroll into a course using the online enrollment system.
He/she must be a student of the school in order to enroll a course. After that, he/she can browse through the list of available courses of the department that he/she is belong to. The basic information of each course including course title, prerequisites, teacher and duration of each course are listed so that student can choose the one that he/she wants to enroll into.
13. Let's start picking out the candidate classes by selecting noun/noun phrases that are likely to be classes.
14. Obviously "student" is a candidate class in the enrollment system. Let's select the word "student" in the problem statement and drag it over the candidate class pane to create a candidate class.
15. Follow the previous step to create candidate classes for the words "course", "school", "department" and "teacher". The resulting textual analysis document should look like the figure below.
|
To see the interactive tutorial of this section, please click here.
|
1. Start Eclipse/IBM WSAD®, then select the File menu > Import... to import the sample project.
2. Select Existing Project into Workspace, then click Next > to continue.
3. Click Browse... to select the "SchoolForDesign" sample project folder, then click Finish to import the project.
4. Select the Window menu > Open Perspective > Java to open the Java perspective.
5. Right-click on the SchoolForDesign project node inside the Package Explorer and select Open UML Model from the popup menu to start SDE.
6. Activate the diagram Use Case Diagram1. Right-click on the use case "Enroll into a course" and select Use Case Description... from the popup menu.
7. When the Use Case Description dialog box appears, double-click on the Value column of the Name field and type "Enroll into a course". After that, press the hot key Ctrl + Enter to confirm.
8. Move the mouse pointer over the bottom margin of the field Brief Description until it changes to a resize handle. Click and drag downwards to resize this row so that there is enough space for the description.
9. Double-click on the Value column of Brief Description and fill in the following description:
After the student logged in to the system, a list of courses will be displayed for selection. The student can select a course interested to view its details.
10. In the Flow of Events field, double-click on the Actor input cell of the last row. Enter "login" to add an actor input.
11. Double-click on the System Response cell of the last row, enter "course list" to add a system response.
12. Add an actor input "view course detail" below "course list".
13. Add a system response "course detail" below "view course detail".
14. The resulting flow of events should look like the figure below.
15. Click OK to finish editing the use case description.
16. Right-click on "Enroll into a course" and select Generate Sequence Diagram from the popup menu to generate a sequence diagram from the flow of events.
17. A sequence diagram will be generated.
18. Let's rearrange the captions so that they match the associated messages.
19. Rename "Actor" to "Student" and rename "System" to "Enrollment System".
20. Right-click on the message "course list" and select Return from the popup menu to change it to a "return" message.
21. Use the same method to change "course detail" to a "return" message.
22. Activate the Diagram Tree, right-click on "Sequence Diagram1" and select Rename... from the popup menu.
23. Enter "Enroll into a course (system level)" in the input dialog box. After that, click OK to confirm.
24. Activate the diagram Use Case Diagram1, right-click on "Enroll into a course" and select Sub Diagrams > Sequence Diagram > Create Sequence Diagram from the popup menu.
25. Create an actor "Student".
26. Create an object and name it "Enrollment System".
27. Create a message "login()" from "Student" to "Enrollment System".
28. Create an object "Enrollment System Controller" and place it to the right of "Enrollment System".
29. Create a message "login()" from "Enrollment System" to "Enrollment System Controller".
30. Create an object "Student Repository" and place it to the right of "Enrollment System Controller".
31. Create a message "lookupStudent()" from "Enrollment System Controller" to "Student Repository".
32. Create a message "student info" from "Student Repository" to "Enrollment System Controller" to indicate the student is valid. Change it to a "return" message.
33. Create a message "login success" from "Enrollment System Controller" to "Enrollment System" to notify the system that the login has been successful. Change it to a "return" message.
34. Create a message "course list" from "Enrollment System" to "Student". Change it to a "return" message.
35. Create a message "viewCourseDetail()" from "Student" to "Enrollment System", and a message "viewCourseDetail()" from "Enrollment System" to "Enrollment System Controller".
36. Create an object "Course Repository" and place it to the right of "Student Repository".
37. Create a message "lookupCourse()" from "Enrollment System Controller" to "Course Repository".
38. Create a message "course detail" from "Course Repository" to "Enrollment System Controller" for displaying to the student. Change it to a "return" message.
39. Create a message "course detail" from "Enrollment System Controller" to "Enrollment System", a message "course detail" from "Enrollment System" to "Student". Change both messages to "return" message.
40. Create a message "enroll()" from "Student" to "Enrollment System", a message "enroll()" from "Enrollment System" to "Enrollment System Controller".
41. Create a message "enrollStudent()" from "Enrollment System Controller" to "Course Repository".
42. Create a message "enroll success" from "Course Repository" to "Enrollment System Controller". Change it to a "return" message.
43. Create a message "enroll success" from "Enrollment System Controller" to "Enrollment System", a message "enroll success" from "Enrollment System" to "Student". Change both messages to "return" message.
44. Activate the Diagram Tree, right-click on "Sequence Diagram1" and select Rename... from the popup menu. When the input dialog box appears, enter "Enroll into a course (elaborated)" and click OK to rename the diagram.
45. Activate the diagram Use Case Diagram1, right-click on "Maintain courses" and select Use Case Description... from the popup menu.
46. When the Use Case Description dialog box appears, edit the use case description as in the figure below:
47. Activate the diagram Use Case Diagram1, right-click on "Maintain courses" and select Generate Sequence Diagram from the popup menu.
48. Rearrange the captions so that they match their associated messages.
49. Rename "Actor" to "Course leader" and rename "System" to "Enrollment System".
50. Change "menu" to a "return" message.
51. Activate the Diagram Tree, right-click on "Sequence Diagram1" and select Rename... from the popup menu. When the input dialog box appears, enter "Maintain courses (system level)" and click OK to rename the diagram.
52. Activate the diagram Use Case Diagram1, right-click on "Maintain courses" and select Sub Diagrams > Sequence Diagram > Create Sequence Diagram from the popup menu.
53. Draw the sequence diagram so that it has the content has shown in the figure below.
54. Create an object "Teacher" and place it to the right of "Staff Repository".
55. If you have read the previous chapter "Performing Analysis", you should recall that we have identified the candidate class "teacher" from the textual analysis before. Now let's create a class model from this candidate class so that we can use it in the sequence diagram.
56. Open the textual analysis Enroll into a course, right-click on "teacher" on the candidate class pane and select Create Class Model from the popup menu to create a class from it.
57. Activate the Model Tree and scroll down until you see the class "teacher" just created.
58. Right-click on this class and select Rename... from the popup menu. Enter "Teacher" in the input dialog and click OK to rename the class. We should rename the class so that its name starts with a capital letter to conform to the naming convention of the Java programming language.
59. Switch back to the diagram Sequence Diagram1. Right-click on "Teacher" and select Select Class > Teacher to assign the class to this object (to indicate that this object is an instance of Teacher).
60. Create a "Create Message" from "Enrollment System Controller" to "Teacher" to indicate the creation of a new teacher.
61. Create a message from "Enrollment System Controller" to "Teacher". Right-click on this message and select Call from the popup menu to make it a call message.
62. Right-click on the call message and select Select Operation > Create Operation... from the popup menu.
63. When the Operation Specification dialog box appears, enter "setName" in Name, and select "void" as the Return type.
64. Click to select the Parameters page. After that, click on Add... to add a parameter.
65. In the Parameter Specification dialog box, enter "name" in Name, and type "String" in Type.
66. Click OK in the Parameter Specification dialog box, then click OK in the Operation Specification dialog box to continue.
67. You will see that the message is now associated with the "setName" method of the "Teacher" class.
68. Continue drawing the diagram so that it looks like the figure below.
69. Create an object "Course" to the right of "Teacher.
70. Create a "Create Message" from "Enrollment System Controller" to "Course" to indicate the creation of a course.
71. Create a message "course added" from "Enrollment System Controller" to "Enrollment System", a message "course added" from "Enrollment System" to "Course leader" to notify the course leader that a course has been added. Change both messages to "return" message.
72. Activate the Diagram Tree, right-click on "Sequence Diagram1" and select Rename... from the popup menu. When the input dialog box appears, enter "Maintain courses (elaborated)" and click OK to rename the diagram.
73. We have now finished the sequence diagrams for the use cases. Let' go back to the textual analysis Enroll into a course to create classes for the remaining candidate classes.
74. Right-click on student and select Create Class Model from the popup menu.
75. Do the same for the candidate classes "department", "course" and "school" to create classes for them.
76. Activate the Class Repository Tree and you will see the classes just created. Select all classes, right-click on the selection and select the Form Diagram menu > Customize... to generate a class diagram.
77. When the Form Diagram dialog box appears, enter "School Class Diagram" in Diagram Name and click OK to confirm.
78. Rename all classes so that all of their names are start with a capital letter.
79. Create a package "sch" and drag all classes into this package.
80. Let's create a state diagram for the "Enrollment System Controller" which we have created in the sequence diagrams. Click on the New State Diagram button on the toolbar to create a state diagram.
81. Create an initial state.
82. Create a state from the initial state using resource-centric, name this state "login".
83. Create a state from "login" using resource-centric, name it "viewCourseDetail".
84. Create a state from "viewCourseDetail" using resource-centric, name it "enroll".
85. Create a state from "enroll" using resource-centric, name it "logout".
86. Create a final state from "logout" using resource-centric.
|
To see the interactive tutorial of this section, please click here.
|
1. Start Eclipse/IBM WSAD®, then select the File menu > Import... to import the sample project.
2. Select Existing Project into Workspace, then click Next > to continue.
3. Click Browse... to select the "SchoolForImplementation" sample project folder, then click Finish to import the project.
4. Select the Window menu > Open Perspective > Java to open the Java perspective.
5. Right-click on the SchoolForImplementation project node inside the Package Explorer and select Open UML Model from the popup menu to start SDE.
6. In this project, there is a class diagram "School Class Diagram", it models a simple design of school with basic attributes, operations and associations defined for the classes. However, there is no associated source code with the classes.
7. Activate the Class Repository Tree, right-click on the SchoolForImplementation project node and select Update Project to Code from the popup menu to generate source code for the project.
8. The source codes are generated for the classes.
9. You may notice that the method bodies are empty. Let's open each file and fill in the necessary method implementations. For instance, open the file "Student.java", delete the old "setName" method body and type "this.name = name;".
10. After all the required method implementations are filled in, open the file "Student.java" again and examine its content. You will find that the getter method for the "name" attribute is missing.
11. Let's type the method declaration and implementation code for the "name" getter method right below the "setName" method.
12. Press the hot key Ctrl + S to save the source code. You will see that the "getName" method is reversed to the class "Student" in the class diagram.
13. Navigate to the class "Teacher" in the diagram. Create a subclass "Professor" from "Teacher" using resource-centric.
14. Right-click on "Professor" and select Update to Code from the popup menu to generate source code.
15. The source file is generated for the class "Professor".
16. Rename "Teacher" to "Instructor" in the class diagram.
17. Activate the Class Repository Tree, right-click on the SchoolForImplementation project node and select Update Project to Code from the popup menu to update the changes to the source codes. Note that since the renaming of "Teacher" will affect more than one class in the project (it has a subclass "Professor"), so it is more appropriate to update the whole project instead of updating only the renamed class.
18. Activate the file "Instructor.java", you will see the class declaration is renamed to "Instructor".
19. Activate the file "Professor.java", the super class declaration "Teacher" is updated to "Instructor", too. Note that you have to delete the old import statement "import sch.Teacher;" which is no longer valid.
20. You can see how easy it is to perform implementation using SDE. Just design the system in SDE, synchronize to Eclipse/IBM WSAD®, and SDE will do all the works for you.
|
To see the interactive tutorial of this section, please click here.
|
1. Start Eclipse/IBM WSAD®, then select the File menu > Import... to import the sample project.
2. Select Existing Project into Workspace, then click Next > to continue.
3. Click Browse... to select the "SchoolForRoundTrip" sample project folder, then click Finish to import the project.
4. Select the Window menu > Open Perspective > Java to open the Java perspective.
5. Right-click on the SchoolForRoundTrip project node inside the Package Explorer and select Open UML Model from the popup menu to start SDE.
6. Activate the diagram School Class Diagram, right-click on the class "Teacher" and select Select in Code from the popup menu.
7. Drag and dock the text editor of "Teacher.java" below the class diagram for easier comparison.
8. Right-click on "Teacher" again and select Open Specification... from the popup menu to edit its specification.
9. Enter "A teacher teaches many courses in a school. It has a subclass Professor." in Documentation and select the Abstract checkbox (to make it an abstract class). After that, click OK to confirm.
10. Click once on the tab of "Teacher.java" to deactive the class diagram. You will see the changes are now reflected in the source code.
11. Scroll down the file "Teacher.java" and edit the "setName" method to make it private. Add appropriate documentation to notify other developers about the change.
12. Press the hot key Ctrl + S to save the changes, the UML model is now synchronized with the source code.
13. Click to select the "setName" method in the class "Teacher". After that, press the hot key Alt + Enter to invoke its open specification dialog box.
14. You can see that the "setName" method is now private, with the documentation as specified in the source code.
15. Click Cancel to close the Operation Specification dialog box.
16. Right-click on "Teacher" and select New Operation to add a new operation.
17. Enter "+setNameAndTitle(name : String, title : String) : void" and press the Enter key to confirm.
The "+" sign is UML notation for public visibility
The "setNameAndTitle" accepts two parameters "name" and "title", both
belong to "String" type
Its return type is "void"
18. Right-click "Teacher" and select Update to Code to update the changes to code.
19. Scroll down the file "Teacher.java" to locate the "setNameAndTitle" method. Fill in appropriate implementation code.
20. Activate the Diagram Tree, right-click on Maintain courses (elaborated) and select Open Maintain courses (elaborated) from the popup menu to open this diagram.
21. Scroll down the diagram until you see the message "11: setName()". We should not use the "setName" method anymore as it has been marked as private.
22. Right-click on "Teacher" and select Select Operation > setNameAndTitle(name: String, title: String): void from the popup menu. We select it because it is the only visible method that can modify the name of a teacher object.
23. Some of the previously example are demonstrated using auto synchronization (on deactivation of a class diagram or upon saving of a source file). If you only want to perform code/model synchronization on demand using menus/buttons/popup menus, you need to disable auto synchronization (which is enabled by default).
24. To disable auto synchronization, select the Modeling menu and deselect Auto Synchronization.
|
To see the interactive tutorial of this section, please click here.
|
Patents pending. All rights reserved. |