Читать книгу Fundamentals of UML. Educational manual - Sholpan Jomartova - Страница 4

CHAPTER № 4

Оглавление

Sеquеncе Dіagram

Brief content:

Creating and removing members

Loops and conditions

Creating and removing members

Interaction diagrams (іnteractіon dіagrams) describe the interaction of groups of objects in different contexts of their behavior. UML interaction diagram defines several types, of which the most common are sequence diagrams.

Typically, a sequence diagram describes a scenario. The diagram shows the object instances and messages exchanged between objects within a single use case (use case).

Consider the following scenario: To determine the value of the order is called a team. The object of the order (Order) to view all the items of the order (LіneІtems) and to determine their prices based on the rules of construction products prices in the order line (OrderLіne). Do this for all the order items, the object of the order is to calculate the total discount which is determined individually for each client.

Figure 10 shows a diagram representing the realization of this scenario. The sequence diagram shows the interaction, presenting each participant with his life line (lіfelіne) that goes straight down and organizes posts on the page; Messages should also be read from top to bottom.

One advantage of the sequence diagram is a notation that it is almost not necessary to explain. You can see the copy of the order sends order line posts and getProduct getQuantіtu. You can also see how the order applies to the method itself, and this method sends a message getDіscountІnfo client instance.

However, not all chart shows so well. The sequence of messages getQuantіtu, getProduct, getPrіcіngDetaіls calculateBasePrіce and must be implemented for each order line, while calculateDіscounts method is called only once.

On the following diagram the participants are named using the style «anOrder». In most cases this is perfectly acceptable. A more complete syntax, «the name of the Class», where name and class are optional, but if the class is used, the colon must be present.

Each line has a life of band activity, which shows the range of active participants in the interaction. It corresponds to the time spent in the stack one of the methods party. The language UML band activity is not mandatory, but they are comfortable with the explanation of behavior.

Naming is often useful to establish links between members on the chart. As seen in the diagram, the method call returns getProduct aProduct having the same name and, consequently, the meaning of the same party, aProduct that sends the call getPrіcіngDetaіls. Note that the back arrow is marked only the challenge to show compliance. Many developers use returns for all calls, but it is more convenient to use them only when it gives additional information; otherwise they just make a mess.

The first message is not a participant, who sent it, because it comes from an unknown source. It is called the search message (message found).

Another approach can be seen in Figure 11. The main objective remains the same, but the way the interaction between the participants to solve it completely different. Order asks each order line on his own price (Prіce). The very order line transmits the calculation on – the object product (Product); note how the transfer of the parameter is shown. Likewise for the calculation order discount object invokes a method for the customer (Customer). As for the task the customer requires information from the object of the order, he does recall against an order to obtain the data.


Figure 10. The sequence diagram of centralized management


First, these two charts it is necessary to pay attention to how clearly the sequence diagram shows the differences in the interaction of the participants. This demonstrates the power of interaction diagrams. They are not very good are the details of algorithms, such as loops or conditional behavior, but make absolutely clear calls between the parties and give really clear picture of what kind of processing is performed specific participants.

Second, the difference is clearly visible in the style of interaction between the two. Figure 10 is a centralized control (control centralіzed) when one of the participants largely performs all of the processing, and others provide information. Figure 14 shows a distributed control (dіstrіbuted control), in which the processing is distributed among many participants, each of which carries a small portion of the algorithm.

Both styles have advantages and disadvantages. Most developers, especially beginners in object-oriented programming, the most commonly used centralized management. In many cases, it's easier, because all processing is concentrated in one place; In contrast, in the case of distributed control when trying to understand the program creates a feeling of chasing objects.

Despite this, the more experienced analysts prefer distributed control. One of the main objectives of good design is to localize change. The data and program code to access these data, often change together. Therefore, data placement and access them programs in one place – thefirst rule of object-oriented design.

In addition, distributed control enables to create more opportunities for the application of polymorphism than in the case of conditional logic. If the algorithms determine the prices differ for different types of products, distributed control mechanism allows the use subclasses of product (Product) for the treatment of these options.


Figure 11. The sequence diagram for distributed control


In general, object oriented style is designed to work with a large number of small objects with many small methods, which gives ample opportunity to redefine and change. This style of confusing people who use long procedure; really is the heart of this change of paradigm shift (paradіgm shіft) with object orientation. To teach this difficult. It seems that the only way to truly understand it is to use a distributed control when working in object-oriented environment.

The sequence diagrams to create and delete participants apply some additional notation (Figure 12). In the case of a party need to draw an arrow Communication addressed to the rectangle of the participant. If you use the constructor, the name of the message is optional, but it may be marked with the word «new». If a participant carries something immediately after creation, for example, the request command, it is necessary to start immediately after the activation of the rectangle party.

Remote participants designated a large cross (X). Arrow posts, running in the X, it means that one participant explicitly removes another; X at the end of the life line indicates that the party removes himself.

If the system runs a garbage collector, objects are then removed manually nevertheless be using X indicate that the object is no longer needed and is ready for removal. This should be the case and closing operations, indicating that the object is no longer used.

Loops and conditions

The general problem is to sequence diagrams how to display loops and conditional structure. First of all it is necessary to understand that sequence diagrams are not designed for this. Such control structures best show with the help of activity diagrams, or custom code. Sequence diagrams are used to visualize the process of interaction of objects, not as a means of modeling the control algorithm.

There are additional designations. And for loops, and conditions for interaction use frames (frames іnteractіon), is a means of marking interaction diagrams. Figure 13 shows a simple algorithm based on the following pseudocode.

fоrеach (lіnеіtеm)

іf (prоduct.valuе> $10K)

carеful.dіspatch

еlsе

rеgular.dіspatch

еnd іf

еnd fоr

іf (nееdsCоnfіrmatіоn) mеssеngеr. cоnfіrm

The frame consists mainly of a region sequence chart divided into several fragments. Each frame has an operator, and each moiety may be protected. Table 3 lists common operators for interaction frames. To display the cycle operator is applied to a single loop fragment, and the body is placed in the protection of the iteration. For conditional logic you can use the alt and put the condition in each piece. It will be executed only one fragment, the protection of which is true. For the sole operator of the field, there opt.


Table 3

Common operators for interaction frames


Figure 12. Creating and removing members


Synchronous and asynchronous calls

In UML version 2 shaded arrows show the synchronous message and simple arrows indicate asynchronous message.

If the caller sends a synchronous message (sunchronous message), then he should wait until the message processing is completed, for example, when you call the subroutine. If the caller sends an asynchronous message (asunchronous message), then he can continue to work and not have to wait for a response. Asynchronous calls can be found in multi-threaded applications and middleware, message-oriented. Asynchronous improves the response time and reduces the number of connections, but more difficult to debug.

The difference is subtle image of arrows; they are difficult to distinguish. Therefore, reading the sequence diagram to make assumptions about the synchronicity of mind arrows However, make sure that the author deliberately drew them different.


Figure 13. Frames interaction


When used sequence diagrams

Sequence diagrams should be used when you want to look at the behaviorof several objects within a single use case. Sequence diagrams are good for representing the interaction of objects, but not very suitable for accurate determination of behavior.

If you want to look at the behavior of a single object in several precedents, it is best to use a state diagram. If it is necessary to study the behavior of several objects in a few precedents or streams suitable activity diagram.


1. Sequence diagram is an example of:

a) collaboration diagram;

b) interaction diagram;

c) class diagram;

d) use case diagram.

2. Sequence diagrams depict all the objects that implement functionality of precedent:

a) true;

b) false.

3. Sequence diagrams give a good idea of how to implement a function:

a) true;

b) false.

4. Cooperation and communication diagrams differ with:

a) the fact that collaboration diagrams illustrate how objects interact, and communication diagrams – how these objects interact;

b) do not differ: collaboration diagrams were simply renamed in UML 2.0;

c) the fact that collaborations have spatial organization on a plane, and communication diagrams have linear organization;

d) both a and c.

5. Sequence diagrams can model asynchronous and multi-threaded processes:

a) true;

b) false.

6. Interaction diagrams use transition condition to control when and which frame fragment is executed:

a) true;

b) false.

7. Alt operator called interaction operator or interaction frame:

a) is used to indicate an invalid fragment;

b) simulates additional behavior;

c) helps to realize a condition;

d) simulates parallel workflow.

8. Proper project should include both sequence diagrams and collaboration diagrams:

a) true;

b) false.

9. Object's focus control symbols are used to indicate:

a) object's life time on sequence diagram;

b) object's life time on communication diagram;

c) when an object is created;

d) nothing from above.

10. UML version 2.0 specification uses:

a) nested numbering scheme to indicate temporal order on sequence diagram;

b) nested numbering scheme to indicate temporal order on communication diagram;

c) flat nested numbering scheme to indicate temporal order on sequence diagram;

d) flat numbering scheme to indicate temporal order on communication diagram.

Fundamentals of UML. Educational manual

Подняться наверх