Java modeling: UML workbook: Conditional logic in Part 2 Sequence Diagram Selection from LegendInfo Blog

xiaoxiao2021-03-06  68

Conditional logic in the figure

Granville Miller (RMiller@together@together@togethersoft.com) consultant, Together, Together, June 2001

Granville continues to discuss the "unified modeling language" and sequence diagram drawing. He carefully studied the role of conditional logic during the sequence drawing process and discussed why you want or exclude conditions and loops in the figure. Granville also describes two forms of sequence diagrams - routines and examples - and illustrate their applications in the development cycle.

I have explained in the introductory column that the sequence diagram is used to describe internal behaviors generated over time. Since the system behavior is the result of the message to send messages to each other, the sequence diagram draws the route when the message moves between the objects. In the final analysis, the sequence diagram is interactive. In the previous part, although we describe countless interactions, only a fairly simple figure is created. This time, we will do a further study to see two forms of the sequence diagram specified by UML. These two forms are routine and instances. Let us start from the correct application of each form.

Two types of sequence diagrams of the sequence diagram are used to describe two different types of interactions between objects. A interaction type is a must (MUST) interaction, where object A must send a specific message to the object B. Another interaction type is possible (may) interact, where object A may (but not) send a specific message to the object B. The sequence diagram of these two forms describe these two different types of interactions. Conventional forms describe must interact, while examples describe possible interaction.

A sequence diagram of a conventional form describes the class interactions generated by the initial stimulus. Conventional forms describe all interactions that the initial stimulus can produce. Success and failure conditions are the same as the circulation, conditions, and branches, are part of this figure.

Conventional sequence diagrams contain only one class name in each box in the horizontal axis direction, as shown in Figure 1. Its meaning is that the object behind the interaction is anonymous, and any object of the class can be involved in interaction. Therefore, it must be clearly modeled for all paths. In a conventional sequence diagram, object a must send a message in the model to the object B.

Figure 1. General sequence diagram

The second form of the sequence diagram is an example. The example sequence diagram describes a single message exchange that may occur between two instances. Such a figure will include a variable name and its class type in the box in the horizontal axis direction, as shown in Figure 2. This form does not include circulatory, conditions and branches in a conventional form. In the actual control flow in the system, some assertions performed in the interaction process may be false. If you find that the assertion is fake, all the messages in the instance sequence diagram are empty, and this situation will not appear. The example sequence diagram describes a single case that may not occur.

Figure 2. Example sequence diagram

The example sequence diagram is best suited to model individual schemes in the analysis phase of the software development lifecycle. A conventional sequence diagram can be modeled for the entire use of multiple scenarios. Other types of activities - such as protocol modeling between subsystems or frames and their individual parts - can use any of the forms, depending on the location where the components are in the software development lifecycle. Compared to example forms, conventional morphology is closer to the actual code that appears in the final product.

We use the regular form in the previous column and will continue to study this form here. This time, we will explore the roles of conditional logic played in the regular sequence diagram, through it, let you know more about UML expressed.

The conditional logic regular sequence diagram in the sequence diagram drawings utilizes conditional logic, which is useful for describing the optional flow of the interactive process. Detailed diagrams can be drawn according to the different stages of the software development life cycle. In the analysis phase, you may be willing to exclude the details outside the conditional expression, while in the design phase, you may want the clips of the code to be used in the final product to be included in the conditional expression.

Regardless of the development cycle, with the natural consistency between the sequence diagram and the object-oriented language such as the Java language, the sequence diagram is more and more. For example, consider a bank business application that allows the invoice to accept deposits. In addition to some other matters, the system must prevent banks from paying negative amounts into account credit, as this can cause it from the account. Therefore, the system must have a mechanism for checking all the amounts typed. Listing 1 shows the conditional expressions that make sure the deposit is positive. Listing 1. Method with conditional expression

/ ** this is a method in a teller class ** /

Public void receiversDeposit (Account Account, BigDecimal Deposit)

Throws impropositDepositiveXception {

// check to ensure the Deposit is posacy

IF (deposit.compareto (New

BigDecimal (0.0))> 0) {

Account.credit (deposit);

}

Else {

Throw new improperdepositiveXception ();

}

}

In the analysis phase, you are not very concerned about details, so the picture only needs to indicate that the deposit is positive. In a conventional sequence diagram, the condition serves as a protective mechanism with a message name and is located above the horizontal call arrow. These protection conditions are enclosed in square brackets, placed on the left side of the message name, as shown in Figure 3.

Figure 3. Conditions added during analysis

The relationship between the above methods and sequence diagrams is clear in Figure 4, and we have seen more clear pictures that may be used in the design phase in Figure 4. Of course, there is no display: the else clause is missing. However, the semantic provisions of the message arrow in the figure can only send messages when they are valid.

Figure 4. Clear conditions

You can model the ELSE clause by adding another call arrow to the Teller class and the ImproperDepositiveXception. There will be a condition opposite to IF on this call; in this example, the deposit must be less than or equal to 0. You may wish to model this statement.

Draw a FOR cycle diagram As shown in the above example, a general sequence diagram -, and actually all UML graphs - almost mapped the syntax of the Java language. Therefore, most Java developers have an intuitive understanding of these pictures, and can learn how to use them quickly. To further explore the consistency between conventional sequence diagrams and Java languages, we will draw a for loop map, as shown in Listing 2.

Listing 2. FOR cycle

For (int i = 0; i <4; i ) {

Squareroom.examinecorner (i);

}

In the sequence diagram, iteration is represented by an asterisk (*) before the message name on the horizontal arrow. If the number of iterations is known and fixed - this situation is very rare - this number appears in square brackets behind the asterisk. Because the complex logic of most FOR loop processing is not allowed to statically determine the number of iterations, you do not often use the parentheses of this format. Figure 5 shows a sequence diagram of the above for cycle.

Figure 5. For cycle sequence diagram

Draw the While loop map Because the While loop combines the loop and condition, it is an example of very easy acceptance. We will draw a diagram of the While displayed in Listing 3.

Listing 3. While cycle

While (Value.notfound ()) {

Value = Database.search (key);

}

Our WHILE loop maps include both conditions, but also an asterisk indicating iteration, but you will find that there is no overlap. While loop rarely contains iterative times - unless it is a camouflage for loop. Figure 6 shows the While loop map. Figure 6. WHILE cycle sequence diagram

Conclusion In general, must be a basic concept of UML and software development. Use an example capture must be active; the scheme captures possible behavior. Class map capture must be active; instance map capture possible behavior. I mainly discuss this concept because I found that many people have failed to master the fundamental flexibility of the sequence diagram, and differentiation into intuitive and form use these two extremes.

When reading these articles, you should focus on the intuitive understanding of development model semantics. With more and more sequence diagrams and start to create their own sequence diagrams, you will find that many sequence diagrams are required to illustrate the required system views in the conditional logic and chart context. As we go deep into more complex chart drawing technology, how to identify and use this difference earlier will help you in the future.

In addition to exploring the importance of sequence drawing, you must introduce you how to indicate conditions and iterations in the figure. Since you already know how to draw For and the While loop map, I recommend that you practice modeling on other Java constructs (such as do-while loops). As you practice these simple textures, you will naturally deepen understanding of the sequence drawing.

Reference

Participate in the discussion forum on the article by clicking on the top or bottom of this article. For the introduction of "Unified Modeling Language" and sequence diagram, please refer to the first column of this series. To learn more about UML and sequence drawing, please take a closer look at the UML Toolkit (John Wiley & Sons, 1997) of Hans-Erik Eriksson and Magnus Penker. Another very helpful resource is UML IN A Nutshell, from Sinan Si Alhir (O'Reilly & Associates, 1998). The "UML Standard" authority authoritative source is the Unified Modeling Language Specification (Version 1.4) when writing this article. For other information about sequence diagrams and UML, see "Building a UML Sequence Diagram with Style, by Scott W. Ambler (DeveloperWorks, February 2001). Allen Holub provides an in-depth explanation of the use case solution in his series of object-oriented design processes (United States, January 2001). Read OCL, it is the UML expression language. IBM and other industry leaders have created XMI, a new open industry standard, which combines some of the advantages of Web-based XML standards such as XML standards such as web-based, confirming, and shared document formats.

Author Blog:

http://blog.9cbs.net/legenDinfo/

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

New Post(0)