PowerDesigner (7) – Object-oriented model (with example, sequence diagram, class diagram, generating Java source code and Java source code generation class)

The original text is from: http://www.voidcn.com/article/p-owwcfxjt-oy.html

Object-oriented model< /h4>

The object-oriented model is a model that uses UML (Unified Modeling Language) graphics to describe the system structure, and it realizes the working status of the system from different angles. These graphics help users, administrators, system analysts, developers, testers and other personnel to exchange information. Here we mainly introduce use case diagrams, sequence diagrams and class diagrams.

1. Object-oriented model OOM

Object-oriented model is a model that uses UML graphics to describe the system structure, and can be created using PowerDesigner’s object-oriented model. PowerDesigner supports the following UML graphics.

  • User Case Diagram: usually used to define the high-level sketch of the system, it Describes the system functions of the application from the user’s point of view, and points out the external operators of each function.
  • Sequence Diagram: Describe how the system actually completes the functions defined in the User Case diagram. You can draw the timing relationship between the objects (instances of the class) when they interact.
  • Class Diagram: Describe the static relationship between classes. Including a series of packages, classes, interfaces and their relationships. Class diagrams are the basis for defining other diagrams.

2. Create an object-oriented model

(1) Select the File-New Model command or click the New Model icon in the toolbar, the New Model window pops up.

(2) Select the Object-Oriented Model option in the Model type column on the left, and enter the model name and language on the right, as shown in Figure 8-1.

Figure 8-1

(3) Click the “OK” button to enter the OOM design workspace. In this workspace, you can define OOM attributes and operations, and you can also design various UML graphics.

(4) Select the Model-Model Properties command to display the OOM Model Properties window as shown in Figure 8-2.

Figure 8-2

(5) After the definition, click the “OK” button. Then select the File-Save As command to save the defined model with the name PubInfoSys.OOM.

(6) Set the model selection. Select the Tools-Model Options command to open the Model Options window. As shown in Figure 8-3.

Figure 8-3

(7) Click the Set As Default button to set as the default option, and then Click the OK button.

3. Design use case diagram

3.1 Use case diagrams are used in the system requirements analysis phase to carry out system requirements and functional design. It contains two elements: executor and use case. The executor refers to the user’s role in the system, and the use case is an interaction between the user and the computer. Use case diagrams are mainly used to describe which executors will participate in each use case.

  • Define the use case: a use case is a system function unit visible from the outside, and these functions are provided by the system unit , Expressed through a series of messages exchanged between units and one or more participants.
  • Defining roles: A role describes a group of users who interact with the system. The most obvious role is the person in the system, but it may also be the system itself.
  • Define association: In addition to being associated with its participants, a use case can also participate in multiple relationships in the system, allowing the defined association to be associated, extended, and generalized, including.

3.2 Define the use case diagram

Define the use case diagram as follows:

(1) Click the “use case” icon Define 4 use cases, as shown in Figure 8-4 Show.

Figure 8-4

(2) Select the first use case and double-click to open Use Case Properties. Properties) window, modify the Name property to “Find” and the Code property to Search, as shown in Figure 8-5.

Figure 8-5

(3) Using the same method, modify the properties of the other 3 use cases as shown in the figure Shown in 8-6.

Figure 8-6

(4) Click the “executor” iconDefine 3 performers, as shown in Figure 8-7.

Figure 8-7

(5) Select the first executor and double-click to open the Actor Properties window , Modify the Name attribute to “Customer” and the Code attribute to Buyer, as shown in Figure 8-8.

Figure 8-8

(6) Use the same method to modify the properties of the other two performers .

(7) Define the relationship between the executor and the use case. Click the “Relationship” icon , then click the executor “customer” and drag the mouse to the use case “find”, release the mouse, then the establishment between the executor and the use case relation. Double-click the relationship to open the Association Properties window, modify the Name attribute to “Query Product”, and modify the Code attribute to SearchProduct.

(8) Follow the method of step (7) to establish relationships between other actors and use cases.

(9) The use case diagram after the definition is completed is shown in Figure 8-9.

Figure 8-9

4 Design sequence diagram

4.1 Sequence Diagram is used to describe how the system implements the functions defined in the Use Case diagram. You can draw the timing relationship that occurs when the objects interact. It describes an interaction on the one hand, involving classes in the class diagram, and on the other hand, it refines the description of the use case.

The sequence diagram has several elements such as Actor, Object, Message and Activation, as shown in 8-10.

Figure 8-10

The message types are:

  • Message:Message
  • Slef Message recursive message
  • Call Message message with activation period
  • Self Call Message with activation period recursive message
  • Return Message return message
  • Self Return Message recursive return message

< p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-s ize:14px; line-height:26px"> 4.2 Create sequence diagram

(1) Select the File-New Model command to open the New Model window. Select the Object-Oriented Model option in the Mode type column on the left side of the window, select the Sequence Diagram option in the First diagram drop-down list box on the right, and select the Java option in the Object language drop-down box, as shown in Figure 8-11.

Figure 8-11

(2) After selecting, click the “OK” button, Enter the PowerDesigner design workspace.

(3) Click the Object icon on the Palette toolbar, click the mouse in the blank work area on the right, the object symbol appears as shown in Figure 8-12.

Figure 8-12

(4) Right-click in the blank area of ​​the design area, and the mouse pointer will turn into an arrow Shape, double-click the object symbol, the Actor Properties window pops up, enter “Caller” in the Name text box, enter “Caller” in the Code text box, and then click the “OK” button.

(5) Repeat steps (3)(4) to add two other objects, the Name is “Switch” and “Called Party”, and the Code is Exchange and Receiver.

(6) Click the Message icon in the Palette toolbar, click on the dotted line below the “caller” object, and drag the mouse to the dotted line below the “switch” object Release the mouse to add a message.

(7) Right-click in the blank area of ​​the design area, the mouse pointer will turn into an arrow shape, double-click the object symbol, the “Message Properties” window will pop up, enter “pick up the microphone” in the Name text box, and enter “in the Code text box Lift Reciever”, and then click the “OK” button.

(8) Repeat (6)(7) and add other messages.

(9) The final sequence diagram is shown in Figure 8-13.

Figure 8-13

(10) Select the File-Save command to save the newly created object-oriented model< /p>

5 Design class diagram

The class diagram uses an abstract method to describe objects and the relationship between them, and cannot describe all the details of the objects.

5.1 Create Class

(1) Select the File-New Model command to open the New Model window. Select the Object-Oriented Model option in the Mode type column on the left side of the window, select the Class Diagram option in the First diagram drop-down list box on the right, and select the Java option in the Object language drop-down box, as shown in Figure 8-14.

Figure 8-14

(2) Click in the Palette toolbar in the class diagram workspace Class icon, create a class, double-click the graphic symbol of the class diagram to open the Class Properties window.

(3) Select the Detail tab to define more attributes of the class.

(4) Select the Attributes tab to add attributes to the class. Click the Add a Row icon to add attributes, or click the Add Attributes icon to open the attributes of other classes in the Selection window list model, select the required attributes, and then click the “OK” button.

(5) Select the Operations tab and click the Add Operation icon to open the Selection window, from which you can select the operations contained in other classes in the model. After selecting, click the OK button, and the selected operation can be added to the current class.

(6) Select the Inner Classifies tab to define internal classes for this class. The internal class is a classifier of PowerDesigner. In UML, the classifier is a model element that contains attributes and operations. After the definition is complete, you can observe the internal class code contained in the current class or interface through the Preview tab, as shown in Figure 8-15.

Figure 8-15

(7) In addition to the above attributes, you can also define Associations, Identifies and other attributes. The content created after the attribute is defined is shown in Figure 8-16.

Figure 8-16

5.2 Create contact

In In the class diagram, there are associations, dependencies, generalizations, and realization associations.

6. Generate Java source code

Show the class diagram in Figure 8-17 to generate Java source code.

Figure 8-17

(1) Select Language-Generate in the class diagram The Java Code command opens the Generation window and displays the classes contained in the model.

(2) Select the class in the Classes tab of the Selection tab, and enter the target path of the Java source code in the Directory column.

(3) Define the Java generation options in the Options tab.

(4) Define the Java generation task options in the Tasks tab, as shown in Figure 8-18.

Figure 8-18

(5) Click the “OK” button to start Generate Java source files, and display the Generated Files window when the generation is complete.

(6) Select a source file, click the Edit button, and the content of the file will be displayed in the text editor. As shown in Figure 8-19.

Figure 8-19

7. According to the Java code Generate class diagram

(1) Select File-Reverse Engineer-Object Language to pop up as shown in Figure 8-20.

Figure 8-20

(2 ) Select Java in the Object language column, and click OK to enter the following interface, as shown in Figure 8-21.

Figure 8-21

(3) Click Add, add a Java file, and then click OK to generate the corresponding Java class diagram (you can also select Java bytecode file or file directory in the Reverse engineer column), as shown in Figure 8-23.

Figure 8-23

Leave a Comment

Your email address will not be published.