UML sequence diagram

xiaoxiao2021-03-05  34

Donald Bellibm 255 February 15th

From Rational Edge: As part of a series of articles on a series of articles on the basic diagram of unified modeling languages, this article provides a detailed introduction to the sequence diagram. It also introduces several new symbol components for the nearest UML 2.0 specification.

It is now in February, and now you may have read, or heard people talk about UML 2.0 - a new specification that includes several advanced UMLs, what changes are made. Considering the importance of new specifications, we are also modifying the foundation of this article, transfer our attention from the OMG UML 1.4 specification to Omg's adopted UML 2.0 draft specification (also name UML 2). I don't like it in the middle of a series of articles, the focus is changed from 1.4 to 2.0, but the UML 2.0 draft specification is an important step in progress, I feel that I need to expand the text.

Due to some reasons, OMG improved UML. The main reason is that they hope that the UML model can express the model-driven architecture (MDA), which means that UML must support more model-driven symbols. At the same time, the UML 1.x symbol set is sometimes difficult to apply to larger applications. In addition, in order to make the graph to become easier to read, improve symbol components are required. (For example, the model logic flow of UML 1.x is too complicated, sometimes it is impossible. The change of the symbolic set of sequence diagrams in UML 2 has made great progress in serialization logic modeling).

Note the text as described above: "The UML2.0 draft specification is adopted." "Indeed, the norm is still in the state of draft, but the key is that the draft specification has been used by OMG, and OMG is a new standard is quite reliable, it will adopt them organization. The specification will have some modifications before UML 2 is fully employed, but these changes should be extremely small. The main changes will be internally in UML - including software companies that are typically implemented by UML tools.

The main purpose of this article is to continue to put our focus on the foundation UML map; this month, we further understand the sequence diagram. Please note again, the examples provided below are based on the new UML 2 specification.

The purpose sequence diagram of the drawing is mainly used to display these interactions between objects in a range of sequences of interaction. Very like class diagram, developers generally believe that the sequence diagram is only meaningful to them. However, an organization's business person will find that the sequence diagram shows how different business objects interact, which is useful for how the current business is available. In addition to the current incident of the recording organization, a sequence graph of a business level can be used as a demand file to implement a future system delivery demand. In the demand phase of the project, analysts can bring the use case into the next level by providing a more formal hierarchy. In that case, use cases often refine into one or more sequence diagrams.

Organizational technicians can find that the sequence diagram is very useful in recording a future system behavior. In the design phase, architects and developers can use the map, excavate the interaction between system objects, so that the entire system design is enriched.

One of the main purposes of the sequence diagram is to transform the needs of the use case, converted to further, more formal levels of fine expression. Use examples are often refined into one or more sequence diagrams. In addition to the design of new systems in design, the sequence diagram is also used to record a presence system (called its "heritage") how to interact now. This document is useful when handing over this system to another person or organization.

Sign Since this is the first article I am based on UML 2 UML chart series, we need to discuss a complement to the UML 2 diagram symbol, ie a symbol component called a frame. In UML 2, the frame element is used as a basis for many other charts, but most people are the case of the frame element for the first time, as the graphical boundary of the figure. When the graphical boundary is provided, a frame element provides a consistent position for the label of the figure. The frame element in the UML figure is optional; as you can see in Figures 1 and 2, the label of the figure is placed in the upper left corner, in I will call the "namebox" of the frame, a roll rectangle And the actual UML map is defined in a larger closed rectangle. Figure 1: Empty UML 2 Frame Element

In addition to providing a graphical border, the frame elements used in the figures also have an important function of describing interaction, such as a sequence diagram. A sequence reception and sending message (also known as interaction) on the sequence diagram, can be established by connecting the message and the frame element boundary to the frame element boundary (see also shown in Figure 2). This will be introduced in more detail in the "transcendence" paragraph.

Figure 2: Sequence diagram for receiving and sending messages

Note In Figure 2, for the sequence diagram, the label of the figure begins by the text "SD". When a picture is enclosed using a frame element, the label of the figure needs to follow the following format:

Figure type diagram name

The UML specification provides a specific text value to the graph type. (For example, the SD represents a sequence diagram, Activity represents the activity diagram, and the use case represents examples.

The main purpose of the base sequence diagram is to define the event sequence and generate some desired output. The focus is not the message itself, but the order of the message; however, most sequence diagrams represent what message passed between objects, and the order they happen. The graph is transmitted according to the horizontal and vertical dimension: the vertical dimension from top to the time series, and the horizontal dimension represents the object instance sent to the left to right.

Life line When drawing a sequence diagram, place the lifeline symbol component, across the top of the diagram. Life line represents the role or object instance of modeling in the sequence. 1 Life line painting a checkered, a dashed line from top, through the center of the bottom boundary (Figure 3). Life line name is placed in square.

Figure 3: An example of a Student class for a lifeline called Freshman

UML's lifeline naming standard is based on the following format:

Entity name: class name

In the example shown in FIG. 3, the lifeline represents the entity of class Student, and its entity name is Freshman. Attention here, the lifeline name is underlined. When using underscores, it means that the lifeline in the sequence diagram represents a particular entity of a class, not a particular type of entity (eg, a role). In a future article, we will understand structured modeling. Now, only the sequence diagrams may contain roles (such as buyers and sellers) without the need to describe those characters (such as Bill and Fred). This allows for the graph of different contexts to reuse. Simple drag and drop, the instance name of the sequence diagram has an underscore, and the character name is not.

In Figure 3, our lifeline example is a named object, but not all lifelines represent named objects. Conversely, a lifeline can be used to show an anonymous or unnamed entity. When in a sequence diagram, when modeling an unnamed instance, the name of the lifeline is the same as the same model as a named instance; but the location of the lifeline name leaves blank, not an example of illustration name. Refer to Figure 3 again, if the lifeline is expanding an anonymous example of the Student class, the lifeline will be: "student". At the same time, because the sequence diagram is used in the project design phase, there is an unspecified object being completely legal: For example, "Freshman". The message is for readability, the first message of the sequence diagram is always starting from the top and is generally located on the left side of the figure. Then, the secondary message is added to the figure, slightly lower than the previous message.

To display an object (for example, a lifeline) to pass a message to another object, you draw a line to the receiving object, including a solid arrow (if it is a synchronous call) or a stick arrow (if it is an asynchronous signal). The message / method name is placed on the line with an arrow. A message that is transmitted to the receiving object, indicating an operation / method of the class implementation of the received object. In the example of Figure 4, an Analyst object calls an instance of an instance of the Reportingsystem class. Analyst object GetAvailableReports method in calling the system object. The system object then calls the SECSYSTEM object, including the parameter userid's GetSecurityClearance method, the type of the class of Secsystem's class is SecuritySystem. 2

Figure 4: Example of a message between an object

In addition to only the message call on the sequence diagram, the maps in FIG. 4 also include a return message. These return messages are optional; one return message is painted with a broken line with open arrows, pointing backwards to the lifeline of the source, on this dashed line, where you place the return value of the operation. In FIG. 4, the Secsystem object returns Userclearance to the system object when the GetSecurityClearance method is called. When the GetAvailableReports method is called, the system object returns AvailableReports.

Further, the return message is a selectable portion of the sequence diagram. Returns the use of the use dependent modeling of modeling. If you need better avatars, the return message is useful; otherwise, the active message is sufficient. I personally like it. Whenever I return a value, I also include a return message because I find that additional details make a sequence diagram easier to read.

When the sequence diagram is modeled, sometimes an object will need to pass a message to itself. When is an object call it itself? A purification theater will argue an object should never pass a message to itself. However, in order to pass a message to its own object modeling, it may be useful in some situations. For example, Figure 5 is an improved version of Figure 4. Figure 5 shows a system object that calls its DETERMINEAVAILAREPORTS method. By indicating that the system passes the message "DETERMINEAVAILALEREPORTS" to itself, the model focuses on the process of the process, not the system object.

In order to draw an object that calls itself, if you usually make, draw a message, but it is not connected to another object, but you connect the message back to the object itself.

Figure 5: System object calling its DETERMINEAVAILAREPORTS method

The message instance in Figure 5 displays synchronization messages; however, in the sequence diagram, you can also model asynchronous messages. A asynchronous message is similar to a synchronized picture, but the message draws a stick with a stick, as shown in Figure 6. Figure 6: Distance to the sequence picture segment of the asynchronous message passing to the entity 2

When the constraint is modeled as an object's interaction, sometimes it is necessary to meet a condition, and the message will pass to the object. Constraints are used in the UML map for control flow. Here, I will discuss the constraints of UML 1.x and UML 2.0. In UML 1.x, a constraint can only be assigned to a single message. In the UML 1.x, in order to draw a constraint on a sequence diagram, you put the constraint elements on the constrained message line, the message name. Figure 7 shows a fragment of the sequence diagram, and there is a constraint on the address.

Figure 7: A fragment of the UML 1.x sequence diagram, where the AddStudent message has a constraint

In Figure 7, the constraint is text "[PASTDuebalance = 0]". Through the constraint on this message, the AddStudent message will be passed if the Accounting System returns a zero point. The symbol of the constraint is simple; the format is:

[Boolean Test]

for example,

[pastduebalance = 0]

Combined debris (variant schemes, selection, and cycles) However, in most sequence diagrams, UML 1.x "in-line" constraint is not enough to handle the required logic of the modeling sequence. This function is missing is a problem with UML 1.x. UML 2 has been resolved by removing "in-line" constraints, adding a symbol component called a combined fragment to solve this problem. A combined fragment is used to combine a set of messages to display conditional branches in a sequence diagram. The UML 2 specification indicates 11 types of interactions of combined debris. Three of the eleven kinds will introduce in the "basis" paragraph, and the other two types will be introduced in the "Transcending Foundation", and the remaining six will be reported in another article. (Hi, this is an article instead of a book. I hope that you will finish this part in the day!)

Variant variants are used to indicate the choice between two or more message sequences. 3 variants support the modeling of the classic "if Ten else" logic (for example, if I buy three, then I get the 20% discount I purchased; otherwise I got 10% discount on I purchased).

As you will notice in Figure 8, a combined fragmentation element of a variant is drawn using a frame. The word "alt" is placed in the framebox of the frame. The larger rectangular is then divided into UML 2. 4 Operation is separated by a broken line. Each operation element has a constraint for testing, and this constraint is placed on the upper left of the operating element of the top of the lifeline. 5 If the constraint of the operation element is equal to "True", then the operation element is the operation element to be executed.

Figure 8: A sequence picture segment containing variant combined debris

Figure 8 is an example of how to read a combined fragment of a variant, and the display sequence begins at the top, that is, the Bank object acquires the check amount and account balance. At this time, the variant combination fragment in the sequence diagram is taken over. Because constraints "[Balance> = Amount]", if the balance exceeds or equal to the amount, then the Bank object is delivered to the ADDDEBITTRANSACK message to the Account object. However, if the balance is not more than or equal to the amount, then the order-in the process is Bank to deliver the AddInSuffientFundfee and the NOTERETURNEDCHECK message to the Account object, the ReturnCheck message gives it itself. Because "ELSE" is constrained, the second sequence is called when the balance is not greater than or equal to the amount. In the combined fragment of the variant, "ELSE" constraint is not required; if an operation element does not have a clear constraint above it, the "ELSE" constraint will be assumed. The combined fragment of the variant is not limited to the simple "if Ten Else" verification. A large amount of variant path may be required. If you need more variant schemes, you must do all the jobs to add an operational dollar in a rectangular shape with sequence constraints and messages. The selection selection combined fragment is used to model the sequence, which gives a specific condition, which will occur; or the sequence does not occur. A selection is used to model simple "if then" expression. (For example, if the loop on the rack is less than five, then do two coil pieces).

The selection combination fragment symbol is similar to the variant combination debris, except that it only has an operation element and never has "ELSE" constraint (it is so, there is no reason). To draw a choice of item combination, you draw a framework. The text "OPT" is the text placed in the frame of NameBox, in the content area of ​​the frame, the constraint of the selection is placed on the top left of the top of the lifeline. The message sequence of the selected item is then placed in the remaining position of the content area of ​​the frame. These components are shown in Figure 9.

Figure 9: A sequence picture segment including selecting a combination fragment

Reading the selection combined fragment is easy. Figure 9 is a further processing of the sequence picture segment of Figure 7, but this time it uses a selection entries combined fragment, because if the overdue balance of Student is equal to 0, there is a need to pass more messages. According to the sequence diagram of Fig. 9, if the overdue balance of Student is equal to zero, then communications, GetCostofClass, and ChargeForClass messages are passed. If the overdue balance of Student is not equal to zero, then in the selection combination fragment, the sequence does not pass any of the messages.

The sequence picture segment of Example Figure 9 includes a selection item constraint; however, the constraint is not a necessary element. In a high level, in an abstract sequence diagram, you may not want to narrate the condition of the selection. You may just want to point out the clip is optional.

The loop sometimes needs to model a repeated sequence. In UML 2, it has been modified for a repetitive sequence, and a circulating combination fragment is attached.

The circulatory combination debris surface is very similar to select item combination debris. You draw a framework, place the text "loop" in the frame of the frame. In the content area of ​​the frame, the top of a lifeline is placed in the upper left corner. The looped message sequence is then placed in the remainder of the framework content area. In a cycle, in addition to the standard Boolean test, a constraint can test two specific conditions. A specific constraint condition is written "minint = [the number]" (for example, "minint = 1") minimum loop number, and writing "maxint = [the number]" (for example, "maxint = 5") Cycles. With the minimum cycle test, the loop must run at least the number of specified times, and the number of cyclic execution cannot reach the maximum number of cycles specified by the constraint. Figure 10: A sequence diagram example of cyclic combination debris (click to enlarge)

The loop running in Figure 10 is run until the HasanotherReport message of the ReportSenu object returns FALSE. If the cycle sequence should be run, the loop of this sequence diagram uses a Boolean test confirmation. In order to read this picture, you will start peace, starting from the top. When you reach the cycle combination fragment, do a test, see if the value HASANOTHERREPORT is equal to TRUE. If the HasanotherReport value is equal to TRUE, the sequence enters the circulating piece. Then you can track the loop in the sequence diagram as in the normal situation.

Beyond the foundation, I have already introduced the basis of the sequence diagram, which should make it possible to model most of the interaction that will usually occur in the system. The following paragraph will introduce a relatively high-order symbol component for the sequence diagram.

Reference another sequence diagram When you do a sequence diagram, developer loves in their sequence diagram, reuses the sequence diagram. 7 Start in UML 2, introduce "interaction" components. The additional interaction can be said to be the most important innovation in the interaction model of UML 2. The interaction increases the function, and organizes the original sequence diagram into a complex sequence diagram. Because of this, you can combine (reuse) a simple sequence to generate a more complex sequence. This means that you can complete the complete, abstract, abstract, to a single conceptual unit.

A interaction element uses a framework. The text "REF" is placed in the NameBox of the frame, and the referenced sequence diagram name is placed in the content area of ​​the frame, together with any parameters of the sequence diagram. The name symbol of the reference sequence diagram is as follows:

Sequence map [(parameter)] [: return value]

Two examples:

1.

Retrieve Borrower Credit Report (SSN): BorrowercreditReport

or

2.

Process Credit Card (Name, Number, ExpirationDate, Amount: 100)

In Example 1, the syntax call is called a sequence diagram of Retrieve Borrower Credit Report, passed to it parameter SSN. Sequence Retreive Borrower Credit Report Returns the variable BorrowerCreditReport.

In Example 2, the syntax call is called the sequence diagram of Process Credit Card, passed to it parameters name, number, expensive date, and amount. However, in Example 2, the AMOUNT parameter will be a value of 100. Since the example 2 does not return value tags, the sequence does not return a value (assuming, the modeling sequence does not need to return value).

Figure 11: A sequence diagram of two different sequence diagrams

Figure 11 shows a sequence diagram that references the sequence diagram "Balance Lookup" and "Debit Accent". The sequence begins with the upper left corner, and the customer passes a message to the Teller object. The Teller object passes a message to the IRBank object. At that time, call the Balance Lookup sequence diagram, and AccountNumber as a parameter. The Balance lookup sequence diagram returns the Balance variable. Then check the constraints of the selection of the sub-combination debris, confirm the balance greater than the amount variable. When the balance is more than the amount, the DEBIT ACCOUNTNUMBER and AMOUNT are transferred to it. After that sequence is complete, the WITHDRAWCASH message returns Cash. It is important to note that in Fig. 11, the Life of THEIRBANK is interactive to hide it. Because interacting hidden lifelines, the TheirBank Life Wire is referenced in the "Balance Lookup" sequence diagram. In addition to hiding the lifeline in the interaction, UML 2 also indicates that the lifeline must have the same THEIRBANK in its own "Balance Lookup" sequence.

Sometimes, you model a sequence diagram, where interacting will overlap without the lifeline referenced in the interaction. In that case, the lifeline is displayed as the normal lifeline, and it is not hidden by overlapping interaction.

In Fig. 11, the sequence references the "Balance Lookup" sequence diagram. The "Balance Lookup" sequence diagram is shown in Figure 12. Because the example sequence has parameters and a return value, its label - in NameBox in the figure - according to a specific mode:

Figure type diagram [Parameter type: parameter name]

[: Return value type]

Two examples:

1.

SD Balance Lookup (Integer: AccountNumber): Real

or

2.

SD Available Reports (FINANCIAL Analyst: Analyst): Reports

Figure 12 illustrates Example 1, in which the Balance Lookup sequence uses the parameter AccountNumber as a variable in the sequence, and the sequence diagram displays the returned REAL object. In this case, the returned object is a sequence diagram entity name.

Figure 12: A sequence diagram using an AccountNumber parameter and returns a real object

FIG. 13 illustrates an example 2, inside, a sequence diagram acquisition a parameter and returns an object. However, the parameter in Figure 13 is used in the interaction of the sequence.

Figure 13: A sequence diagram of using parameters in its interaction, returning a sequence diagram of a Reports object

The paragraph in front of the door demonstrates how to pass information through parameters and return values, reference another sequence diagram. However, there is another method to deliver a message between the sequence diagram. The door may be an easy way to model the transmission message between the sequence diagram and its context. A door is just a message, the graph is representative as the edge of the frame of one end connection, and the other is connected to the lifeline. Figure 11 and 12 of the door can be seen in Figures 14 and 15. The example of Figure 15 shows an entry gate called GetBalance, acquisition parameter accountnumber. Since it is connected to the frame of the arrow to the frame, the arrow is connected to the lifeline, so the getBalance message is an entrance gate. The sequence diagram also has a door, returning the Balance variable. The export door is known, because it is a return message, connects from a lifeline to the frame, arrow connection frame.

Figure 14: Reconstruction of Figure 11, this time

Figure 15: Reconstruction of Figure 12, this time

Combined debris (jump and parallel) present in the "foundation" paragraph in front of this article, I introduced the "variant", "selection", and "cyclic" combined fragments. These three combined debriss are most useful. However, there are two other combination debris, and a large number of shared people will find useful - jump and parallel. Jump jump combine fragments are almost consistent with the selection combination fragment in each aspect, except for two exceptions. First, the frame of the jump frame nameBox is "Break" instead of "option". Secondly, when a message running a jump combined fragmentation, the other news of the closed interaction will not be executed because the sequence breaks the closed interaction. Thus, the jump combination fragment is very like a Break keyword in the programming language of C or Java.

Figure 16: Reconstruction from the sequence picture segment from Figure 8, the fragment uses jump instead of variants

Jump is most commonly used to do model abnormal processing. Figure 16 is a reconstruction of Figure 8, but this time Figure 16 uses jump combination fragments because it treats Balance

Note An important thing about jump is that they only cause a sequence of closed interactions to exit, and do not have to complete the sequences described in the figure. In this case, the jump combination is a portion of the variant or cycle, and then only the variant or cycle is quit.

Today's modern computer systems continue to improve in complexity and sometimes implement concurrent tasks. When completing a complex task, some systems use part of the parallel processing process than the desired time. When creating a sequence diagram, when displaying parallel processing activities, you need to use parallel combined fragmentation elements.

Parallel combination debris uses a frame to paint, you put the text "Par" in the framebox of the frame. Then you divide the content segment of the frame into a horizontal operating element. Each operation element of the frame represents a thread running in parallel.

Figure 17: Oven is an object instance for parallel to two tasks

Figure 17 may not illustrate the best computer system examples of objects for parallel activities, but provide an example of an easy-to-understand parallel activity sequence. The sequence is in this way: HungryPerson passes the cookfood message to the Oven object. When the OVEN object receives that message, it simultaneously sends two messages (Nukefood and RotateFood) to itself. After these messages are processed, the HungryPerson object returns YummyFood from the Oven object.

Summary sequence diagram is a good picture for recording system requirements, and finishing system design. The sequence diagram is such a reason to use because it displays the interaction logic between the objects in the system in the time order of interaction.

reference

UML 2.0 SuperStructure Final Adopted Specification (Chapter 8) http://www.omg.org/cgi-bin/doc?ptc/2003-08-02 UML 2 SEQUENCE DIAGRAM overview http://www.agilemodeling.com/ Artifacts / Sequencediagram.htm UML 2 Tutorial http://www.omg.org/news/meetings/workshops/uml 2003 manual/tutorial7-hogg.pdf footnotes 1 in a fully modeled system, object (instance) It will also be modeled in the system's class diagram.

2 When reading this sequence diagram, assume that the analyst is within the system.

3 Note that the two or more constraints that attach to different variant operations can indeed true, but only one operating dollar will occur at runtime (in that case variants in the case). "WINS" is not defined in accordance with the UML standard).

4 Although the operation is very similar to the road on the road, I especially not call them a small way. The lane is the UML symbol used on the activity map. Please refer to the article of the Rational EDGE on the articles about the activity map.

5 Typically, attached to the constraints is a lifeline that has a variable contained in a constraint expression.

6 About selecting a combination of fragments, cyclic combination debris does not need to place a constraint condition on it.

7 may reuse any type of sequence diagram (for example, programs or services). I just discovered that developers prefer to decompose their pictures by function.

Reference

You can see this article in our website on our world.

About the author Donald Bell is an IT expert in IBM global service, where he and IBM customers are committed to designing and developing software solutions. J2EE.

转载请注明原文地址:https://www.9cbs.com/read-32520.html

New Post(0)