5BUIS017W BIS Design and Architecture Lecture Week 4 PDF

Document Details

PureQuadrilateral

Uploaded by PureQuadrilateral

University of Westminster

Tags

UML interaction diagrams sequence diagrams object diagrams

Summary

This document presents a lecture on interaction diagrams, specifically sequence and communication diagrams, for BIS Design and Architecture. Details about the different components of these types of diagrams are explained.

Full Transcript

5BUIS017W BIS Design and Architecture LECTURE, WEEK 4 TOPIC(S): INTERACTION DIAGRAMS: SEQUENCE &COMMUNICATION DIAGRAMS Content of this presentation Last week we concluded with class design diagram. This week we’ll discuss “object diagram” (from last week) Both (class – object diagrams) are structu...

5BUIS017W BIS Design and Architecture LECTURE, WEEK 4 TOPIC(S): INTERACTION DIAGRAMS: SEQUENCE &COMMUNICATION DIAGRAMS Content of this presentation Last week we concluded with class design diagram. This week we’ll discuss “object diagram” (from last week) Both (class – object diagrams) are structure diagrams Then, we’ll continue with “interaction diagrams” that is a sub-category of behaviour diagrams We’ll examine: ❖ Sequence diagrams in detail ❖ Communication diagrams Interaction diagrams are “dynamic” diagrams. 2 Object diagram (from week 3) Similarly to class diagram, object diagram is a structure diagram. Object diagram aims to model instances of the system It is a snapshot of the objects in a system And relationships that exist among those objects At specific point in time Objects are created at run-time as instances of classes Objects encapsulate their data 3 Object diagram (from week 3) Object Notation of object diagram Slot Remark: different than class diagram: only 2 slots Object: Relationship The name of the object Slot: Values Relationships https://www.linkedin.com/learning/software-design-modeling-with- uml/object-diagram?autoplay=true&resume=false&u=42314660 4 Object diagram (from week 3) An object diagram derives from a class diagram. When we create an object diagram, we must always work according and in relation to the description given in the class diagram Object: name followed by “:” followed by the name of the classifier, underlined We can omit the name of the object and just have :clasiffier_name, underlined ➔ anonymous object Slots: values of class attributes; not necessarily all attributes, only those that are important for what we model. Slots do NOT include METHODS (structural) Class diagram Object diagram Relationships: the same as in class; same names, same notations 5 Object diagram (from week 3) Example from Udemy course “Master UML - A Complete Unified Modeling Language Guide”, instructor: Amit Chugh Can you identify the classes that participate in the class diagram 6 Class diagram vs Object diagram (from week 3) Class diagram Object diagram Static aspect of a system Behaviour of a system in real time No values of an instance Includes attributes and data values of an instance Behaviours No behaviours Represents abstract model consisting Represents an instance at a of classes and their behaviour particular moment which is concrete in nature Number of class diagrams are limited We could have unlimited number of instances – each one unique 7 Dynamic modeling – intro to interactive diagrams Class & object diagrams are structure diagrams The next group of diagrams we’ll discuss, are “interaction diagrams” (sub-category of behaviour diagrams) Interaction diagrams are “dynamic” diagrams. Definition of a dynamic model: o Describes the components of the system that have interesting dynamic behavior There are two main UML diagram types for dynamic modeling (both behaviour diagrams): o Sequence diagrams describe the dynamic behavior between objects/classes o State machine diagrams describe the dynamic behavior of a single object/class. One state diagram for each class with interesting dynamic behavior o Classes without interesting dynamic behavior are not modeled with state diagram 8 Dynamic modeling – intro to interactive diagrams Dynamic Interaction diagrams: Sequence Diagram: o Describes the dynamic behavior of several objects over time o Good for real-time specifications Collaboration Diagram: o Shows the temporal relationship among objects o Position of objects is based on the position of the classes in the UML class diagram. o Does not show time 9 Dynamic modeling – intro to interactive diagrams Dynamic (non-interactive, behaviour) diagrams: State Chart Diagram: o A state machine that describes the response of an object of a given class to the receipt of outside stimuli (Events). Activity Diagram: o A special type of state chart diagram, where all states are action states (discussed last year) 10 Dynamic modeling – basic concepts The purpose of dynamic modeling is to: o Detect and supply operations for the object model. How do we identify operations? o We look for objects, that are interacting and extract their “protocol” o We look for objects, that have interesting behavior on their own o Good starting point: Flow of events in a use case description o From the flow of events, we proceed to find the participating objects. 11 Dynamic modeling – basic concepts What is an event? o Something that happens at a point in time o An event sends information from one object to another o Events can have associations with each other: o Causally related: o An event happens always before another event o An event happens always after another event o Causally unrelated: o Events that happen concurrently Events can also be grouped in event classes with a hierarchical structure => Event taxonomy 12 Dynamic modeling – basic concepts The term “event” is often used in two ways: Instance of an event class: o “Slide 14 shown on Thursday May 9 at 8:50”. o Event class: “Lecture Given”, Subclass “Slide Shown” Attribute of an event class o Slide Update(7:27 AM, 05/10/2024) o Train_Leaves(4:45pm, London Euston) o Mouse button down(button#, tablet-location) 13 Dynamic modeling – basic concepts Identify events Use case: ‘check out’ system for an e-commerce site (previous weeks’ example). Basic scenario 1 2 4 ◦ Users browse through 3 the site. They place items it in the shopping cart. In order to buy a product, they must register, create an account and become “customers”. 4 ◦ Customers set an order by providing payment and shipping information. ◦ Then the system validates payment information, responds with 5 order confirmation of, and provides order number that the customer can use to check on the order status. Step 1: Look for objects that interact. Step 2: Identify flow of events Step 3: Put the events in the correct order; identify if they are causally related (one before or after another) or causally unrelated (happen at the same time) 14 Sequence diagrams Sequence diagrams are the most common interaction diagrams and among the most common UML diagrams A sequence diagram shows how a set of objects interact in a process over time (importance of time / duration) It shows the messages that pass between participant and object in the system and the order in which they occur Depicts interaction between objects in sequential order ◦ Messages flow from one object to the other ◦ A message flow is represented using a dotted line extended across the bottom of the page Sequence diagrams are used by developers to model the interaction in a single use case; they illustrate: ◦ how the different parts of a system interact with each other to carry out a function and ◦ the order in which that interaction occurs when a particular use case is executed 15 Sequence diagrams Typically, they are used to represent the detailed object interaction that occurs for one use case or for one operation. They are used to show interaction is sequential order. They are often generated as an outcome of refinement of use case Can be drawn at different levels of detail and to meet different purposes at several stages in the development life cycle. 16 Sequence diagrams Advantages: By capturing the communication among classes, they help us to identify the behaviour that we need to implement in the code They may be used for designing new systems or depicting interactions in existing systems They help us to understand how the control/events flow between the objects. They are useful to stakeholders to understand system’s behaviour 17 Sequence diagrams – participants Participants A participant is some part in the system that interacts with other parts (Class? Object? Actor?) Participants are always placed at the top of the diagram and they are arranged horizontally. For a participant we could use the name of a class or the name of an object or both. Notation: Object A: Class A peter: User Ordering is very important in sequence diagram; the ordering is represented through time as lifelines Each participant has a corresponding lifeline that runs down the page In a sequence diagram there are two life lines: https://www.linkedin.com/learning/software-design- modeling-with-uml/sequence-and-communication- o From top to bottom: flow of time; one for each participant diagram?autoplay=true&resume=false&u=42314660 o Left to right and/or right to left: flow of messages 18 Sequence diagrams – messages Interaction Messages An interaction allows participants to communicate with each other Obj1: Class1 Obj2: Class2 start Activation bar indicates execution and it is only optional; Activation bar represents time but not duration message Activation bar indicates that the object is alive is memory, waiting for the return interaction to be completed message Communication happens via messages to self A message can flow to o From a participant to another participant and back o From a participant and self A message may optionally show the message signature The interaction is triggered with a “start” message: o It comes from unknown entity o It is called “found” message 19 Sequence diagrams – messages A message could appear with or without arguments What is the meaning of the sequence diagram on the right? 20 Sequence diagrams – messages Types of messages There are the following types of diagrams: o Synchronous o Asynchronous o Return o Create and Destroy 21 Sequence diagrams – messages Types of diagrams Synchronous message Synchronous A message that has to wait till next message Asynchronous Execute several interactions at the same time Asynchronous execution might be required o for preventing the user interface from getting blocked o Execute multiple tasks at the same time for efficiency Return A “reaction” from a participant Asynchronous messages Usually a message is related to the operation of a class Return message 22 Sequence diagrams – messages Types of diagrams Create and destroy Create: creates new participant Destroy: destroys participant : What are they??? 23 Sequence diagrams – fragments Sequence diagram might include loops, conditional executions; alternative executions etc; To represent these we use fragments A fragment is represented as a box that encloses interactions ◦ Could contain any number of interactions ◦ Could contain other fragments ◦ The type/name of the fragment goes in the top left corner Types/names of fragments. The two most common are: ◦ Conditions: opt and alt ◦ Loop Two more: ◦ Break ◦ Ref 24 Sequence diagrams – fragments Conditions: ◦ Opt (optional) ◦ Alt (alternative) Opt The interaction in this fragment is executed ONLY if the guard condition is true. “if” (no “else”) Alt More than one guard condition “if … elseif... Else” 25 Sequence diagrams – fragments Loop Continue doing something Stopping condition Loops through the interactions within the fragment any number of times The stopping condition is shown as a guard statement 26 Sequence diagrams – fragments Break “Break” is similar to “option fragment” (opt). Differences: a) use of “break” instead of “opt” b) when a break fragment is to be executed, the enclosing interaction’s remainder messages will not be executed because the sequence breaks out of the enclosing interaction. It treats the condition as an exception instead of as an alternative flow. Breaks are most commonly used to model exception handling. Example: https://developer.ibm.com/articles/the-sequence-diagram/ 27 Sequence diagrams – fragments Ref “Ref” is used to represent an interaction that is defined elsewhere in the model. Sequence diagrams grow quickly; to reduce complexity we could create small chunks of interactions, take them out the main diagram, put them in a separate diagram and create a reference to that diagram, using “ref” fragment Helps to manage the size of large sequence diagrams. Allows us to reuse part of one sequence diagram in another Example: https://creately.com/blog/diagrams/sequence-diagram- tutorial/#:~:text=To%20specify%20the%20reference%20fragment,Part%202%20and%20Part%203 28 Sequence diagrams – further semantics In previous diagrams, we have used classes with no further semantics – most are entity classes. As we discussed in previous week, we also have control and boundary classes. The next step is to model the interaction in more detail by adding boundary and control classes 29 Sequence diagrams – example According to our scenario: Users browse through the site. They place items it in the user1:User cart1:Cart order1:Order shopping cart. In order to buy a product, they must register, create an account and become “customers”. addItem(Item1) Customers set an order by providing payment and update success shipping information. What is missing??? placeOrder “Browse through the site” → Interface --> boundary class success “must register / create account” → Account → control class 30 Sequence diagrams – example user1:User site1:Site cart1:Cart acc1:Account order1:Order browse selectItem(Item1) update addItem(Item1) success createAccount success placeOrder(O1) createOrder(O1) success success More examples: https://sparxsystems.com/enterprise_architect_user_guide/16.0/modeling_languages/sequencediagram.html 31 Sequence Diagram Common Mistakes When drawing sequence diagrams, designers tend to make the following common mistakes. By avoiding these mistakes, you can ensure the quality of your diagram. Adding too much detail. This clutters up the diagram and makes it difficult to read. Obsolete and out-of-date sequence diagrams that are irrelevant when compared to the interfaces, actual architectures, etc. of the system. Don’t forget to replace them or modify them. Leaving no blank space between the use case text and the message arrow; this makes it difficult for anyone to read the diagram. Not considering the origins of message arrows carefully. See these common mistakes explained in detail in Sequence Diagram Guide: Common Mistakes to Avoid When Drawing Sequence Diagrams. 32 Communication diagram “Communication” diagram is another type of “interaction diagram”. In previous versions of UML it had the name “collaboration diagram” The main difference between communication diagram and sequence diagram is that the objects in the communication diagram, do not have a lifeline. The focus of the communication diagram is on how objects are linked through messages – the focus is on link, rather than the order. They offer the big picture view of the interactions between objects of the system. 33 Communication diagram Basic elements: Participants: ◦ Represented by rectangle ◦ Name of participant and its class are placed in the rectangle as: :; both can be specified or left anonymous Communication links ◦ Single line that connects participants. Messages passed along the link ◦ Filled arrow from sender to receiver ◦ Name and (optional) list of parameters ◦ Number before the name that shows the order Examples in slides 29, 30, 31 from Udemy course: “Object Oriented Analysis, Design & Programming with UML”, instructor: Umar Lone 34 Communication diagram A message that is invoked through another message is called “nested message” The number scheme uses the same base message number, followed by another number (e.g. 1.1 or 3.1 as in the example) Concurrent messages are allowed. 35 Communication diagram Conditions could be added and loops are allowed as well as messaged to itself The looping statement is shown with an asterisk before the looping constrain as well as messaged to itself 36 Communication diagram Sequence and communication diagrams 37 Sequence vs Communication diagram Sequence Diagram Communication Diagram Shows the sequence of messages Focuses on the links and the organisation of objects Lifeline of objects No lifeline of objects More detailed; more information Simpler; less information Consumes horizontal space Requires less space Difficult to use during Easier to create during brainstorming brainstorming More difficult to see the sequence of Message order is depicted clearly messages 38 Next week Today we concluded with “object diagram” (from last week) and “structured diagrams”; Then we discussed sequence and communication diagrams. Both interaction diagrams. Next week we’ll discuss state machine diagram; State machine diagram is a “behaviour diagram” 39

Use Quizgecko on...
Browser
Browser