1. Trang chủ
  2. » Công Nghệ Thông Tin

Hiểu biết về mô hình hóa động

50 5 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 50
Dung lượng 1,01 MB

Nội dung

Một thiết kế hướng đối tượng đại diện cho những khía cạnh cấu trúc và hành vi của một hệ thống phần mềm. Mô hình tĩnh được sử dụng để đại diện cho các thành phần cấu trúc của một hệ thống phần mềm. Mô hình năng động, được sử dụng để đại diện cho hành vi của các thành phần cấu trúc. Năng động, mô hình sử dụng các loại khác nhau của sơ đồ, chẳng hạn như sự tương tác, nhà nước, và sơ đồ hoạt động. Chương này giải thích các khái niệm về mô hình năng...

An object-oriented design should represent the structural and behavioral aspects of a software system Static modeling is used to represent the structural constituents of a software system Dynamic modeling is used to represent the behavior of the structural constituents Dynamic modeling uses various types of diagrams, such as interaction, state, and activity diagrams This chapter explains the concept of dynamic modeling In addition, it explains how to create the dynamic model of a system by using interaction diagrams Objectives In this chapter, you will learn to:  Identify the concepts of dynamic modeling  Create interaction diagrams Chapter Understanding Dynamic Modeling Introducing Dynamic Modeling Concepts Dynamic modeling is a UML modeling technique that represents the behavior of the static constituents of a software system Therefore, it is also known as behavioral modeling A designer requires dynamic modeling techniques to represent the interaction, workflow, and different states of the static constituents in a software system Need for Dynamic Modeling The design of a software system is considered to be the good if it is able to represent what a system should and how Without a good design a developer will not be able to code a program correctly This is because coding involves the implementation of the design Modeling techniques are required to represent all aspects of a software system These modeling techniques help in representing the system requirements, the static constituents of a system, its behavior, and architecture Dynamic modeling techniques help the designer to represent the behavior of the static constituents so that a developer is able to depict how a system should behave to meet the desired requirements It provides various diagrams such as, interaction, activity, and state diagrams, which help you design the dynamic model of a software system Consider the example of Wilson Inc., an automobile manufacturing company, which is planning expansion and, for this reason, wants to automate its inventory control The management of Wilson Inc decides to install an inventory management system (IMS) that will organize the stock reorder level, supplier details, and payments for spare parts records The task of developing the IMS is entrusted upon a development team that creates a dynamic model of the IMS to understand the interaction between the various components of the software system The dynamic model of the IMS is created using various diagrams, such as interaction, state, and activity diagrams The interaction diagram models the interaction between the static constituents of a software system The activity diagrams represent the sequence of activities that the static constituents of a system need to perform to complete a process and the state diagrams depict the changes that occur in the state of objects because of the interaction among the various constituents of a software system ÔNIIT Understanding Dynamic Modeling 7.3 Difference between Static and Dynamic Modeling Static modeling is required to represent the physical structure of a software system However, it is insufficient as it does not explain how the constituents of the structure behave and interact with each other To depict the behavior of the structural constituents, you need dynamic modeling The following table lists the differences between static and dynamic modeling Static Modeling Dynamic Modeling It represents the static or structural constituents of a software system Therefore, it is also known as structural modeling It represents the behavior of static constituents of a software system Therefore, it is also known as behavior modeling It includes class and object diagrams It includes interaction, activity, and state diagrams It helps in depicting the relationships and dependencies between the constituents of a system It helps in expressing and modeling the behavior of a system over a period of time Difference between Static and Dynamic Modeling 7.4 Understanding Dynamic Modeling ÔNIIT Creating Interaction Diagrams Interaction diagrams depict how the constituents of a software system interact to realize the use cases of the system In addition, you can use interaction diagrams to generate executable code through forward and reverse engineering The two components of an interaction diagram are: „ Collaboration: Depicts the static aspect of an interaction diagram „ Interaction: Depicts the dynamic aspect of an interaction diagram A collaboration is a collection of instances of classes, the relationship among the instances of classes, and actors A collaboration groups all the components that are required to realize a use case The relationships among the components of a collaboration are graphically depicted as links between objects A link serves as a path over which messages are sent and received Note Although, abstract classes and interfaces not have instances, they can form a part of a collaboration You use interactions to depict the flow of control in an operation or among use cases In an interaction, an object sends a message to request another object to perform an operation In other words, an interaction is initiated when one object requests another object to perform certain operations, and in this way, invokes its methods For example, Wilson Inc has an inventory database that stores the inventory information when a new stock of automobile parts arrives The inventory manager intimates the supplier and orders automobile parts when the stock of a part reaches its reorder level To design the IMS, the development team creates a collaboration for the use case, order parts, which is realized through the interaction of Order object and the inventory database The various interactions to realize the use case, order parts are: Request by the Inventory Manager actor to the object, O1 of class Order, to perform the operation, issueOrder() Request by the issueOrder() operation to the database to store the information about the order Signal sent by the database to the object, O1, to intimate that the data storage operation is complete ÔNIIT Understanding Dynamic Modeling 7.5 The following figure shows the flow of control to realize the order parts use case of the IMS Interaction Diagram for the Order Parts Use Case There are multiple slots in a collaboration, called roles, which are filled by objects and links at run time In other words, roles are used to depict the run-time responsibility of the objects of a class and the relationship The two types of roles in a collaboration are: „ Classifier roles: Describe objects that can form a part of the collaboration „ Association roles: Describes the links that can form a part of the collaboration Note An interaction signifies the collection of communications that occur among the classifier roles across the association roles A collection of communications indicates the messages that flow from one classifier role to another 7.6 Understanding Dynamic Modeling ¤NIIT When an object calls the methods of another object, a sequence of messages flow between them The following table lists the various types of messages that can be sent from one object to another and their graphical representation in an interaction diagram Message Description Call Specifies the invocation of a method of an object Return Returns a value to the calling method Send Sends an asynchronous signal to an object Create Creates an object Destroy Destroys an object Graphical Representation The commonly used interaction diagrams are Sequence diagram and Communication diagram Let us, discuss how to create these diagrams Creating Sequence Diagrams Sequence diagrams represent an interaction among objects in the form of messages ordered in a sequence by time In a sequence diagram, you arrange objects across the x-axis You place the object that starts an interaction to the extreme left The objects that come later in the message sequence are placed to the right of the interaction-initiating object The messages sent and received by the objects in an interaction are placed along the y-axis in an increasing order of time ÔNIIT Understanding Dynamic Modeling 7.7 The following figure depicts the arrangement of objects and messages in a sequence diagram Arrangement of Messages and Objects in a Sequence Diagram An object may be created or destroyed when an operation is performed You can use sequence diagrams to depict the creation and destruction of an object In addition, sequence diagrams depict the change in the focus of control of an object in the form of a rectangular bar The length of rectangle bar represents the duration of time for which an object interacts with another object The following figure depicts a sequence diagram that shows how an object is created and destroyed, the focus of control, and the object lifeline Object1 Object Lifeline Object2 Message Focus of Control Focus of Control and Object Lifeline in a Sequence Diagram 7.8 Understanding Dynamic Modeling ÔNIIT In the preceding figure, Object1 creates Object2 and subsequently sends a message to it When Object2 completes its processing, it is destroyed Consider the following sequence diagram for the Order Parts use case of the IMS system Sequence Diagram for the Order Parts Use Case In the preceding figure, the Inventory Manager creates an instance of the order class and invokes the issueOrder() method of the order class The order object stores the details in the Inventory Database When the details are stored in the database, the order object receives a Transaction Complete signal and is then destroyed When an object invokes its own method or receives a callback from another object, a new focus of control is represented over the existing focus of control and is called a nested focus of control ÔNIIT Understanding Dynamic Modeling 7.9 The following figure shows the nested focus of control of an object Nested Focus of Control Note Unlike sequence diagrams, communication diagrams not depict the object lifeline In a sequence diagram, the flow of control depicts a sequential flow of messages However, a programming logic may require you to depict the iterations of messages or the branching of the flow of control Iterations are repetitions of messages You can use the following statement to depict an iteration in a sequence diagram: *[ j := n ] You use an asterisk, *, to indicate that the message is being sent repeatedly You can depict iteration by using the following notations: „ [j < 10]: Specifies that the message will be sent until the value of j is less than 10 „ [val not found]: Specifies that the message will be sent until val is found 7.10 Understanding Dynamic Modeling ÔNIIT 11 Drag the Association Role symbol ( ) from the UML Collaboration (Metric) stencil on the drawing page to draw the relationship between DisplayScreen and Transaction classifier roles, as shown in the following figure Relationship between DisplayScreen and Transaction Classifier Roles 12 Double-click the association role symbol A UML Association Role Properties dialog box appears 7.36 Understanding Dynamic Modeling ÔNIIT 13 Select Initiate Transaction from the Base Association drop-down list in the UML Association Role Properties dialog box, as shown in the following figure UML Association Role Properties Dialog Box Note Two classifier roles in a communication diagram can be connected by using an association role only if the classes corresponding to the two classifier roles are connected through an association in the corresponding class diagram Note If in the UML Association Role Properties dialog box, the Base association drop-down list is disabled, there may be two possible reasons for that: „ The corresponding base association does not exist in the class diagram „ The direction of the association in the communication diagram needs to be reversed For example, if End1 of the association role is connected to ClassifierRoll1 and End2 of the association role is connected to ClassifierRole 2, you may need to connect End1 to ClassifierRole and End2 to ClassifierRole ÔNIIT Understanding Dynamic Modeling 7.37 Note Base Association drop down list will have different values for different Associations depending upon the relationship created between the classes in the class diagram 14 Click the OK button The following figure shows the association relationship between DisplayScreen and Transaction classifier roles Relationship between DisplayScreen and Transaction Classifier Roles 7.38 Understanding Dynamic Modeling ÔNIIT 15 Double-click the association role symbol connecting the DisplayScreen and Transaction classifier roles to display the methods associated with the association role The UML Association Role Properties dialog box appears 16 Select Messages from Categories section in the UML Association Role Properties dialog box The Messages section appears as shown in the following figure Messages Section in UML Association Role Properties Dialog Box 17 Select Message1 in the Messages section and click the Properties button The UML Message Properties dialog box appears 18 Type SelectTransaction in the Name text box 19 Select forward from the Direction drop-down list and StartTransaction from the Operation drop-down list ÔNIIT Understanding Dynamic Modeling 7.39 20 Type 12: in the Sequence expression text box, as shown in the following figure , UML Message Properties Dialog Box 21 Click the OK button The UML Association Role Properties dialog box appears and displays the changed properties for the message 7.40 Understanding Dynamic Modeling ÔNIIT 22 Click the OK button The message appears with the association role, as shown in the following figure Message Associated to a Relationship 23 Right-click the association role symbol connecting the DisplayScreen and Transaction classifier roles and select the Shape Display Options option The UML Shape Display Options dialog box appears ÔNIIT Understanding Dynamic Modeling 7.41 24 Clear the Message arguments check box in the General options section and click the OK button The message appears as shown in the following figure Message with Arguments Removed 25 Double-click the association role symbol connecting DisplayScreen and Transaction to display other associated messages The UML Association Role Properties dialog box appears 26 Select Messages from Categories section in the UML Association Role Properties dialog box The Messages section appears 7.42 Understanding Dynamic Modeling ÔNIIT 27 Click the New button A new message is added in the Messages section as shown in the following figure Messages Section in UML Association Role Properties Dialog Box 28 Click the Properties button The UML Message Properties dialog box appears 29 Type Prompt in the Name text box 30 Select backward from the Direction drop-down list and Prompt from the Operation drop-down list ÔNIIT Understanding Dynamic Modeling 7.43 31 Type 13: in the Sequence expression text box, as shown in the following figure , UML Message Properties Dialog Box 32 Click the OK button 7.44 Understanding Dynamic Modeling ÔNIIT 33 Similarly, add the other messages between DisplayScreen and Transaction classifier roles The following figure represents the messages associated with the DisplayScreen and Transaction classifiers Messages between DisplayScreen and Transaction Classifiers Note To represent the self association you can use Association role ( of Association role( these symbols ÔNIIT ) symbol instead ) symbol There is no difference between the functionality of Understanding Dynamic Modeling 7.45 34 Similarly, draw the relationship between all other classifier roles and display the messages associated with them, as shown in the following figure Communication Diagram for the ATM System 35 Save and close the Bank _ATM model 36 Close Microsoft Visio 7.46 Understanding Dynamic Modeling ÔNIIT Practice Questions Dynamic modeling is also known as: a Static modeling b Structural modeling c Behavioral modeling d System modeling Which of the following diagrams is included in static modeling? a Class diagram b Interaction diagram c Activity diagram d State diagram Which of the following diagrams is used to represent an interaction among objects in the form of messages ordered in a sequence by time? a Sequence diagram b Communication diagram c Timing diagram d Interaction Overview diagram Communication diagram is also known as: a Timing diagram b Collaboration diagram c Interaction Overview diagram d Sequence Diagram Which of the following interaction diagrams is used to represent the changes in state and value of an object over a period of time? a Sequence diagram b Timing diagram c Communication diagram d Interaction Overview diagram ¤NIIT Understanding Dynamic Modeling 7.47 Summary In this chapter, you learned that: „ Dynamic modeling is used to understand the interaction among objects and the states of objects of software systems „ Interaction diagrams show an interaction between the objects of a collaboration There are four types of interaction diagrams: sequence, communication, timing, and interaction overview „ Sequence diagram is a type of interaction diagrams that is used to model the flow of control by time ordering „ Communication diagrams represent the interaction among objects in the form of messages 7.48 Understanding Dynamic Modeling ÔNIIT Exercises Exercise Blue Valley Consulting Inc decides to further enhance the functionality of the system that will enable the Operations Manager to enter details of transactions on monthly basis This functionality will also provide a user interface that will allow the Operations Manager to add, modify, and delete cash flows To implement this functionality, you need to incorporate two modules The details of these modules are as follows: MODULE: RECORD TRANSACTIONS Using the Record Transactions module, the Operations Manager can enter the transaction date and amount for the lease payment for a particular property The Record Transactions module will be invoked when either a new property is leased or a change to the property information occurs MODULE: MAINTAIN SCHEDULE OF CASH FLOW This module will provide a user interface where the Operations Manager can enter and review the cash flows The user interface will also allow the Operations Manager to enter cash flow repeatedly until a given date Create the sequence and communication diagrams for the two modules Hint: To complete this exercise, you need to use the Visio file that you created for Exercise of Chapter ÔNIIT Understanding Dynamic Modeling 7.49 7.50 Understanding Dynamic Modeling ÔNIIT

Ngày đăng: 11/05/2021, 03:37

w