In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the UML sequence chart example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
The purpose of the picture
Sequence diagrams are mainly used to show the interactions between objects in the order in which they occur. Much like class diagrams, developers generally think that sequence diagrams only make sense to them. However, business people in an organization will find that sequence diagrams show how different business objects interact and are useful for communicating how the current business is going. In addition to recording the current events of the organization, a business-level sequence diagram can be used as a requirements document to deliver requirements for a future system. During the requirements phase of the project, analysts can take use cases to the next level by providing a more formal level of expression. In that case, use cases are often refined into one or more sequence diagrams.
The organization's technicians can find that sequence diagrams are very useful in documenting how the behavior of a future system should behave. In the design phase, architects and developers can use diagrams to mine the interactions between system objects, thus enriching the entire system design.
One of the main uses of sequence diagrams is to transform the requirements expressed by the use case into a further, more formal level of fine expression. Use cases are often refined into one or more sequence diagrams. In addition to their use in designing new systems, sequence diagrams can also be used to record how objects that exist in the system (called "legacy") now interact. This document is useful when transferring the system to another person or organization.
Symbol
Since this is the first article in my series of UML diagrams based on UML 2, we need to first discuss a supplement to UML 2 graphical symbols, a symbolic element called a frame. In UML 2, frame elements are used as a basis for many other graphic elements, but the first time most people come into contact with frame elements is as a graphical boundary of the diagram. When providing a graphical boundary for a diagram, a frame element provides a consistent location for the label of the diagram. The frame components are optional in the UML diagram; as you can see in figures 1 and 2, the label of the diagram is placed in the upper left corner, in the "namebox" of the frame I will call, a curl rectangle, and the actual UML diagram is defined inside the larger closed rectangle.
Figure 1: empty UML 2 frame element
In addition to providing a graphical border, the frame elements used in the diagram also have important functions to describe interactions, such as sequence diagrams. A sequence receives and sends messages (also known as interactions) on a sequence diagram, and a model can be established by connecting the message and the frame element boundaries (as seen in figure 2). This will be described in more detail in later paragraphs on "beyond the basics".
Figure 2: a sequence diagram of receiving and sending messages
Notice in figure 2 that for sequence diagrams, the label of the diagram starts with the word "sd". When you use a frame element to close a diagram, the label of the diagram needs to be in the following format:
Diagram type graph name
The UML specification provides specific text values for graph types. (for example, sd stands for sequence diagram, activity for activity diagram, and use case for use case diagram).
Basics
The main purpose of a sequence diagram is to define a sequence of events and produce some desired output. The point is not the messages themselves, but the order in which they are generated; however, most sequence diagrams represent what messages are passed between objects in a system, and the order in which they occur. The figure conveys information in horizontal and vertical dimensions: the vertical dimension represents the time series of the message / call from top to bottom, and the horizontal dimension from left to right represents the object to which the message is sent.
Lifeline
When drawing a sequence diagram, place lifeline symbol elements across the top of the diagram. The lifeline represents the role or object instance modeled in the sequence. 1 Lifeline draws a square, a dotted line from the top down, through the center of the bottom boundary (figure 3). The lifeline name is placed in the box.
Figure 3: an example of a Student class for a lifeline of an entity named freshman
The lifeline naming standard of UML is in the following format:
Entity name: class name
In the example shown in figure 3, the lifeline represents the entity of class Student, whose entity name is freshman. Note here that the lifeline name is underlined. When underlining is used, it means that the lifeline in the sequence diagram represents a specific entity of a class, not a specific kind of entity (for example, a role). In a future article, we will learn about structured modeling. Now, just review the sequence diagram and may include roles (such as buyer and seller) without describing who plays those roles (such as Bill and Fred). This allows the reuse of pictures in different contexts. Simple drag-and-drop, the instance name of the sequence diagram is underlined, but the role name is not.
Our lifeline example in figure 3 is a named object, but not all lifelines represent named objects. Instead, a lifeline can be used to represent an anonymous or unnamed entity. When modeling an unnamed instance on a sequence diagram, the lifeline name follows the same pattern as a named instance; but the location of the lifeline name is left blank instead of providing an example diagram name. Referring to figure 3 again, if the lifeline is representing an anonymous example diagram of the Student class, the lifeline would be: "Student". At the same time, because sequence diagrams are used in the project design phase, an unspecified object is perfectly legal: for example, "freshman".
Message
For readability, the first message in a sequence diagram always starts at the top and is usually on the left side of the diagram. Then the secondary message is added to the diagram, slightly lower than the previous message.
To show that an object (for example, a lifeline) sends a message to another object, you draw a line pointing to the receiving object, including a solid arrow (if it is a synchronous invoke operation) or a stick arrow (if it is an asynchronous signal). The message / method name is placed above the line with an arrow. The message being passed to the receiving object represents an operation / method implemented by the receiving object's class. In the example in figure 4, the analyst object invokes the system object of an instance of the ReportingSystem class. The analyst object is calling the getAvailableReports method of the system object. The system object then calls the getSecurityClearance method on the secSystem object, including the parameter userId, whose class type is SecuritySystem. two
Figure 4: an example of passing messages between objects
In addition to displaying only the message calls on the sequence diagram, the diagram in figure 4 also includes the return message. These return messages are optional; a return message is drawn as a dotted line with an open arrow pointing back to the lifeline of the source on which you place the return value of the operation. In figure 4, when the getSecurityClearance method is called, the secSystem object returns userClearance to the system object. When the getAvailableReports method is called, the system object returns availableReports.
In addition, the return message is an optional part of the sequence diagram. The use of the return message depends on the level of concrete / abstraction of the modeling. If better materialization is needed, it is useful to return a message; otherwise, an active message is sufficient. I personally like to include a return message whenever a value is returned, because I find that extra details make a sequence diagram easier to read.
When modeling a sequence diagram, sometimes an object will need to pass a message to itself. When does an object call itself? A purist would argue that an object should never pass a message to itself. However, modeling a message to its own object can be useful in some situations. For example, figure 5 is an improved version of figure 4. The figure 5 version shows the system object that calls its determineAvailableReports method. By indicating that the system passes the message "determineAvailableReports" to itself, the model focuses on the fact of the process rather than on the object of the system.
To draw an object that invokes itself, as you usually do, draw a message, but instead of connecting it to another object, you connect the message back to the object itself.
Figure 5: the system object calls its determineAvailableReports method
The message example in figure 5 shows synchronous messages; however, in the sequence diagram, you can also model asynchronous messages. An asynchronous message is similar to a synchronous representation, but the message is drawn with a stick-shaped spearhead, as shown in figure 6.
Figure 6: a sequence picture segment representing an asynchronous message delivered to entity 2
Constraint
When modeling the interaction of an object, sometimes a condition must be met before the message is delivered to the object. Constraints are found throughout the UML diagram to control the flow. Here, I will discuss the constraints of both UML 1.x and UML 2.0. In UML 1.x, a constraint can only be assigned to a single message. In UML 1.x, to draw a constraint on a sequence diagram, you place the constraint element on the message line of the constraint, before the name of the message. Figure 7 shows a fragment of the sequence diagram with a constraint on the message addStudent method.
Figure 7:UML 1.x A fragment of the sequence diagram in which the addStudent message has a constraint
In figure 7, the constraint is the text "[pastDueBalance=0]". With the constraint on this message, if the accounts receivable system returns a zero overdue balance, the addStudent message will be delivered. The symbol of the constraint is simple; the format is:
[Boolean Test]
For example
[pastDueBalance = 0]
Combined fragments (variants, selections, and loops)
However, in most sequence diagrams, the UML 1.x "in-line" constraint is not sufficient to handle the necessary logic for a modeling sequence. This lack of functionality is a problem with UML 1.x. UML 2 has solved this problem by removing the "in-line" constraint and adding a symbol element called combinatorial fragmentation. A composite fragment is used to group a set of messages together to display bar branches in a sequence diagram. The UML 2 specification specifies 11 types of interaction for composite fragments. Three of the eleven will be introduced in the "basics" paragraph, the other two types will be introduced in "beyond basics", and the remaining six will be introduced in another article. Hey, this is an article, not a book. I want you to finish this part in one day! )
Variant
Variants are used to indicate mutually exclusive choices between two or more message sequences. The 3 variants support classic "if then else" logic modeling (for example, if I buy three, then I get a 20% discount on my purchase; otherwise I get a 10% discount on my purchase).
As you will notice in figure 8, a variant of the composite fragment element is drawn using a frame. The word "alt" is placed in the namebox of the frame. The larger rectangle is then divided into what UML 2 calls an Operand. 4 the operands are separated by dotted lines. Each Operand has a constraint to test, and this constraint is placed on the upper left of the Operand at the top of the lifeline. 5 if the constraint of the Operand is equal to "true", then that Operand is the Operand to be executed.
Figure 8: a sequence picture segment containing a fragment of the variant combination
Figure 8, as an example of how a variant of the combination fragment is read, shows that the sequence starts at the top, that is, the bank object gets the check amount and account balance. At this point, the variant combination fragment in the sequence diagram takes over. Because of the constraint "[balance > = amount]", if the balance exceeds or equals the amount, the bank object then passes the addDebitTransaction and storePhotoOfCheck messages to the account object sequentially. However, if the balance is not more than or equal to the amount, then the sequential process is for bank to pass addInsuffientFundFee and noteReturnedCheck messages to the account object, and returnCheck messages to itself. Because of the "else" constraint, the second sequence is called when the balance is not greater than or equal to the amount. In the combined fragment of the variant, the "else" constraint is not required; if an Operand does not have an explicit constraint on it, the "else" constraint is assumed.
The combined fragments of the variants are not limited to simple "if then else" validation. A large number of variant paths may be required. If you need more variants, all you have to do is add an Operand to a rectangle with sequence constraints and messages.
Select item
Selection combination fragments are used to model sequences that give a specific condition that will occur, or the sequence will not occur. An option is used to model a simple "if then" expression. (for example, if there are less than five doughnuts on the shelf, make another two dozen doughnuts).
The option combination fragment symbol is similar to the variant combination fragment, except that it has only one Operand and can never have a "else" constraint (as it is, for no reason). To draw a combination of options, you draw a frame. The text "opt" is the text placed in the namebox of the frame, and in the content area of the frame, the constraint of the selection is placed in the upper-left corner of the top lifeline. The message sequence of the selection is then placed in the rest of the content area of the frame. These components are shown in figure 9.
Figure 9: a sequence picture segment that includes fragments of the selection combination
It is easy to read the selection portfolio fragments. Figure 9 is a reprocessing of the sequence image segment in figure 7, but this time it combines fragments with an option, because if the overdue balance of Student equals 0, more messages need to be delivered. According to the sequence diagram of figure 9, if the overdue balance of Student is equal to zero, and then the overdue balance of addStudent,getCostOfClass and chargeForClass messages H invalid tudent is not equal to zero, then the sequence does not deliver any message in the selection combination fragment.
The sequence picture segment of figure 9 includes a selection constraint; however, the constraint is not a required element. In a high-level, abstract sequence diagram, you may not want to describe the conditions of the selection. You may just want to point out that the clip is optional.
Cycle
Sometimes you will need to model a repetitive sequence. In UML 2, modeling a repetitive sequence has been improved, with cyclic combination fragments added.
The loop combination shard surface is very similar to the option combination shard. You draw a frame and place the text "loop" in the frame's namebox. In the content area of the frame, at the top of a lifeline, loop constraint 6 is placed in the upper-left corner. The cyclic message sequence is then placed in the rest of the frame content area. In a loop, in addition to standard Boolean tests, a constraint can test two specific conditionals. Specific constraints are the minimum number of cycles to write "minint = [the number]" (for example, "minint = 1") and the maximum number of cycles to write "maxint = [the number]" (for example, "maxint = 5"). Through the minimum loop test, the loop must run at least a specified number of times, and the number of loop execution times cannot reach the maximum number of cycles specified by the constraint.
Figure 10: an example of a sequence diagram of cyclic composite fragments (click to enlarge)
The loop shown in figure 10 runs until the hasAnotherReport message for the reportsEnu object returns false. If the loop sequence should run, the loop of the sequence diagram is confirmed by a Boolean test. In order to read this picture, you start at the top, as usual. When you reach the loop combination fragment, do a test to see if the value hasAnotherReport is equal to true. If the hasAnotherReport value is equal to true, then the sequence enters the loop fragment. Then, as usual, you can track looping messages in the sequence diagram.
Transcend the foundation
I have introduced the basics of sequence diagrams, which should allow you to model most of the interactions that will normally occur in the system. The higher-order symbol elements used in sequence diagrams are described in the following paragraphs.
Reference another sequence diagram
When making sequence diagrams, developers love to reuse existing sequence diagrams in their sequence diagrams. 7 starting with UML 2, the "interaction" component is introduced. Additional interaction can be said to be the most important innovation in UML 2 interaction modeling. Interaction adds the function of organizing the original sequence diagram into a complex sequence diagram. Because of these, you can combine (reuse) simpler sequences to produce more complex sequences. This means that you can abstract a complete and possibly complex sequence into a single conceptual unit.
An interactive component is drawn using a frame. The word "ref" is placed in the namebox of the frame, and the referenced sequence diagram name is placed in the content area of the frame, along with any parameters of the sequence diagram. The name symbol of the reference sequence diagram is as follows:
Sequence diagram name [(parameter)] [: return value]
Two examples:
1. Retrieve Borrower CreditReport (ssn): borrowerCreditReport
Or
2. Process Credit Card (name, number, expirationDate, amount: 100)
In example 1, the syntax calls a sequence diagram called Retrieve Borrower Credit Report, passing it the parameter ssn. The sequence Retreive Borrower CreditReport returns the variable borrowerCreditReport.
In example 2, the syntax calls the sequence diagram called Process Credit Card, passing it the parameters name,number,expiration date, and amount. However, in example 2, the amount parameter will be a value of 100. Because example 2 does not return a value label, the sequence does not return a value (assuming that the modeled sequence does not need to return a value).
Figure 11: a sequence diagram that references two different sequence diagrams
Figure 11 shows a sequence diagram that references the sequence diagrams "Balance Lookup" and "Debit Account". Starting from the upper left corner, the client passes a message to the teller object. The teller object passes a message to the theirBank object. At that time, the Balance Lookup sequence diagram is called, and accountNumber is passed as a parameter. The Balance Lookup sequence diagram returns the balance variable. Then check the constraints of the selection combination fragments to confirm that the balance is greater than the amount variable. When the balance is larger than the amount, call the Debit Account sequence diagram and pass it the parameters accountNumber and amount. After that sequence is completed, the withdrawCash message returns cash for the customer.
It is important to note that in figure 11, the lifeline of theirBank is hidden by interactive Balance Lookup. Because the interaction hides the lifeline, it means that the theirBank lifeline is referenced in the "Balance Lookup" sequence diagram. In addition to hiding the lifeline of 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 the interaction overlaps lifelines that are not referenced in the interaction. In that case, the lifeline is displayed like a normal lifeline and is not hidden by overlapping interactions.
In figure 11, the sequence refers to 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 the namebox of the diagram-- follows a specific pattern:
Diagram type [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, where the Balance Lookup sequence uses the parameter accountNumber as a variable in the sequence, and the sequence diagram shows the returned Real object. In cases like this, the returned object uses the sequence diagram entity name.
Figure 12: a sequence diagram that uses the accountNumber parameter and returns a Real object
Figure 13 illustrates example 2, in which a sequence diagram takes a parameter and returns an object. However, in figure 13, parameters are used in the interaction of sequences.
Figure 13: a sequence diagram that uses parameters in its interaction and returns a Reports object
Door
The previous paragraph shows how to pass information through parameters and return values, referencing another sequence diagram. However, there is another way to pass messages between sequence diagrams. The gate may be an easy way to model the delivery of messages between the sequence diagram and its context. A door is just a message, graphically represented as one end connecting the frame edge of the sequence diagram and the other end connected to the lifeline. Using figures 11 and 12 of the door, refactoring can be seen in figures 14 and 15. The example diagram in figure 15 has an entry gate called getBalance, which gets the parameter accountNumber. Because the line of the arrowhead is connected to the frame of the diagram, and the arrowhead is connected to the lifeline, the getBalance message is an entry door. The sequence diagram also has an exit gate that returns the balance variable. The exit door is known in the same way, because it is a return message that connects the frame from a lifeline to the diagram, and the arrow connects the frame.
Figure 14: refactoring of figure 11, this time using the door
Figure 15: refactoring of figure 12, this time using the door
Combined fragmentation (jump and parallelism)
As presented in the "basic" paragraph earlier in this article, I introduced the combined fragments of "variant", "option", and "loop". These three combined fragments are the ones that most people will use most. However, there are two other combined fragments that a large number of people who share will find useful-jumping and parallelism.
Jump
The jump combination fragment is consistent with the option combination fragment in almost every respect, with two exceptions. First, the text "break" of the jump frame namebox replaces "option". Second, when a message of a jump combination fragment runs, other messages of the closed interaction will not be executed because the sequence breaks the closed interaction. In this way, the jump combination fragment is very similar to the break keyword in C++ or Java's programming language.
Figure 16: reconstruction of the sequence diagram fragment from figure 8, which uses jumps instead of variants
Jumps are most commonly used for model exception handling. Figure 16 is a refactoring of figure 8, but this time figure 16 uses jump combination fragments because it treats the case of balance < amount as an exception rather than a variant flow. To read figure 16, you start at the upper left corner of the sequence and read down. When the sequence reaches the return value "balance", it checks to see if the balance is less than the amount. If the balance is not less than the amount, the next cancellation to be passed is the addDebitTransaction message, and the sequence continues normally. However, in the case where the balance is less than the amount, the sequence then enters the jump combination fragment, and its message is delivered. Once the message of the jump combination has been delivered, the sequence exits without sending any other messages (for example, addDebitTransaction).
One important thing to note about jumps is that they only cause a sequence of closed interactions to exit without having to complete the sequence described in the figure. In this case, the jump combination is part of the variant or loop, and then only the variant or loop is exited.
Parallelism
Today's modern computer systems are constantly improving in terms of complexity and sometimes performing concurrent tasks. When the processing time required to complete a complex task is longer than expected, some systems use parallel processing of all parts of the process. When creating a sequence diagram that shows parallel processing activity, you need to use parallel combination of fragment elements.
Parallel composite fragments are drawn using a frame, and you put the text "par" in the frame's namebox. Then you divide the content segment of the frame into horizontal operands with dotted lines. Each Operand of the framework represents a thread running in parallel.
Figure 17: oven is an object example of doing two tasks in parallel
Figure 17 may not illustrate the best computer system example of an object doing parallel activities, but it does provide an example of an easy-to-understand sequence of parallel activities. The sequence goes like this: the hungryPerson passes the cookFood message to the oven object. When the oven object receives that message, it sends both messages (nukeFood and rotateFood) to itself. After these messages are processed, the hungryPerson object returns yummyFood from the oven object.
Thank you for reading this article carefully. I hope the article "sample Analysis of UML sequence Chart" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.