What symbol is used in UML to indicate a relationship between a class and an interface?
CS2113/T AY1819S1 Show
Class DiagramsIntroductionCan explain/identify class diagrams UML class diagrams describe the structure (but not the behavior) of an OOP solution. These are possibly the most often used diagrams in the industry and an indispensable tool for an OO programmer. An example class diagram: ClassesCan draw UML classes The basic UML notations used to represent a class: A
The 'Operations' compartment and/or the 'Attributes' compartment may be omitted if such details are not important for the task at hand. 'Attributes' always appear above the 'Operations' compartment. All operations should be in one compartment rather than each operation in a separate compartment. Same goes for attributes. The visibility of attributes and operations is used to indicate the level of access allowed for each attribute or operation. The types of visibility and their exact meanings depend on the programming language used. Here are some common visibilities and how they are indicated in a class diagram:
Which of these follow the correct UML notation?
Draw a UML diagram to represent the
💡 You may omit AssociationsCan interpret simple associations in a class diagram We use a solid line to show an association between two classes. This example shows an association between the Can interpret association navigabilities in class diagrams We use arrow heads to indication the navigability of an association.
Here is an example of a bidirectional navigability; each class is aware of the other. Navigability can be shown in class diagrams as well as object diagrams. According to this object diagram the given
(a) Explanation: The diagram indicates that Can explain/use association roles in class diagrams Association Role labels are used to indicate the role played by the classes in the association. This association represents a marriage between a Note how the variable names match closely with the association roles.
The role of
Can explain/use association labels in class diagrams Association labels describe the meaning of the association. The arrow head indicates the direction in which the label is to be read. In this example, the same association is described using two different labels.
Can explain what is the multiplicity of an association Commonly used multiplicities:
In the diagram below, an In the diagram below,
(c)(d) DependenciesCan use dependencies in a class diagram UML uses a dashed arrow to show dependencies. Two examples of dependencies: Associations as AttributesCan show an association as an attribute An association can be shown as an attribute instead of a line. Association multiplicities and the default value too can be shown as part of the attribute using the following notation. Both are optional.
The diagram below depicts a multi-player Square Game being played on a board comprising of 100 squares. Each of the squares may be occupied with any number of pieces, each belonging to a certain player. A The association that a EnumerationsCan interpret enumerations in class diagrams Notation: In the class diagram below, there are two enumerations in use: Show (in UML notation) an enumeration called Class-Level MembersCan interpret class-level members in class diagrams In UML class diagrams, underlines denote class-level attributes and variables. In the class below, Association ClassesCan interpret association classes in class diagrams Association classes are denoted as a connection to an association link using a dashed line as shown below. In this example CompositionCan interpret composition in class diagrams UML uses a solid diamond symbol to denote composition. Notation: A AggregationCan interpret aggregation in class diagrams UML uses a hollow diamond is used to indicate an aggregation. Notation: Example: Aggregation vs Composition 💡 The distinction between composition (◆) and aggregation (◇) is rather blurred. Martin Fowler’s famous book UML Distilled advocates omitting the aggregation symbol altogether because using it adds more confusion than clarity. Which one of these is recommended not to use in UML diagrams because it adds more confusion than clarity?
(b) Class InheritanceCan interpret class inheritance in class diagrams You can use a triangle and a solid line (not to be confused with an arrow) to indicate class inheritance. Notation: Examples: The InterfacesCan interpret interfaces in class diagrams An interface is shown similar to a class with an additional keyword The Abstract ClassesCan interpret abstract classes in class diagrams You can use italics or Example: CombineCan combine different basic aspects of class diagrams Draw a class diagram for the code below. Also draw an object diagram that will represent the object structure after running
Draw a class diagram for the code below. Also draw an object diagram that will represent the object structure after running the code. Make the multiplicities as strict as possible without contradicting the code.
Implement the class structure given below: Suppose we wrote a program to follow the class structure given in this class diagram: Draw object diagrams to represent the object structures after each of these steps below. Assume that we are trying to minimize the number of total objects. i.e. apply step 1 → [diagram 1] → apply step 2 on diagram 1 → [diagram 2] and so on.
After step 2, the diagram should be like this: Sequence DiagramsCan explain/identify sequence diagrams A UML sequence diagram captures the interactions between multiple objects for a given scenario. Consider the code below.
Here is the sequence diagram to model the interactions for the method call Can interpret sequence diagrams with basic notation Notation: This sequence diagram shows some interactions between a human user and the Text UI of a CLI Minesweeper game. The player runs the The Arrows representing method calls should be solid arrows while those representing method returns should be dashed arrows. Note that unlike in object diagrams, the class/object name is not underlined in sequence diagrams. [Common notation error] Activation bar too long: The activation bar of a method cannot start before the method call arrives and a method cannot remain active after the method had returned. In the two sequence diagrams below, the one on the left commits this
error because the activation bar starts before the method [Common notation error] Broken activation bar: The activation bar should remain unbroken from the point the method is called until the method returns.
In the two sequence diagrams below, the one on the left commits this error because the activation bar for the method Can interpret sequence diagrams with object creation Notation:
The Can interpret sequence diagrams with object deletion UML uses an 💡 Although object deletion is not that important in languages such as Java that support automatic memory management, you can still show object deletion in UML diagrams to indicate the point at which the object ceases to be used. Notation: Note how the diagrams shows the deletion of the Can interpret sequence diagrams with loops Notation: The Can interpret sequence diagrams with self invocation UML can show a method of an object calling another of its own methods. Notation: The In this variation, the Can interpret sequence diagrams with alternative paths UML uses Notation: Can interpret sequence diagrams with optional paths UML uses Notation:
Can interpret sequence diagrams with parallel paths UML uses Notation: 💡 If you show parallel paths in a sequence diagram, the corresponding Java implementation is likely to be multi-threaded because a normal Java program cannot do multiple things at the same time. Can interpret sequence diagrams with reference frames UML uses ref frame to allow a segment of the interaction to be omitted and shown as a separate sequence diagram. Reference frames help us to break complicated sequence diagrams into multiple parts or simply to omit details we are not interested in showing. Notation: The details of the Those details are shown in a separate sequence diagram given
below. Can interpret sequence diagrams with minimal notation To reduce clutter, activation bars and return arrows may be omitted if they do not result in ambiguities or loss of information. Informal operation descriptions such as those given in the example below can be used, if more precise details are not required for the task at hand. A minimal sequence diagram Object DiagramsCan explain/identify object diagrams An object diagram shows an object structure at a given point of time. An example object diagram: Can draw UML objects Notation: Notes:
Some example objects: Draw a UML
diagram to represent the
Can interpret simple associations among objects A solid line indicates an association between two objects. An example object diagram showing two associations: Activity DiagramsIntroductionCan explain activity diagrams A UML Activity diagram (AD) can model workflows. Basic NotationsCan interpret linear paths in activity diagrams An activity diagram (AD) captures an activity of actions and control flows that makes up the activity.
Note the slight difference between the start node and the end node which represent the start and the end of the activity, respectively. This activity diagram shows the action sequence of the activity a passenger rides the bus: Which of these activity diagrams use the correct UML notation?
Can interpret alternate paths in activity diagrams A branch node shows the start of alternate paths. Each control flow exiting a branch node has a guard condition : a boolean condition that should be true for execution to take that path. Only one of the guard condition can be true at any time. A merge node shows the end of alternate paths. Both branch nodes and merge nodes are diamond shapes. Guard conditions must be in square brackets. The AD below shows alternate paths involved in the workflow of the activity shop for product: Which of these activity diagrams use the correct UML notation?
Can interpret parallel paths in activity diagrams Fork nodes indicate the start of concurrent flows of control. Join nodes indicate the end of parallel paths. Both have the same notation: a bar. In a set of parallel paths, execution along all parallel paths should be complete before the execution can start on the outgoing control flow of the join. In this activity diagram (from an online shop website) the actions User browsers products and System records browsing data happen in parallel. Both of them need to finish before the log out action can take place. Which of these activity diagrams use the correct UML notation?
Can use rakes in activity diagrams The rake notation is used to indicate that a part of the activity is given as a separate diagram. Here is the AD for a game of ‘Snakes and Ladders’. The rake symbol (in the Can explain swimlanes in activity diagrams It is possible to partition an activity diagram to show who is doing which action. Such partitioned activity diagrams are sometime called swimlane diagrams. A simple example of a swimlane diagram:
NotesCan use UML notes UML notes can augment UML diagrams with additional information. These notes can be shown connected to a particular element in the diagram or can be shown without a connection. The diagram below shows examples of both. Example: Can specify constraints in UML diagrams A constraint can be given inside a note, within curly braces. Natural language or a formal notation such as OCL (Object Constraint Language) may be used to specify constraints. Example: MiscellaneousCan distinguish between class diagrams and object diagrams Compared to the notation for a class diagrams, object diagrams differ in the following ways:
Furthermore, multiple object diagrams can correspond to a single class diagram. Both object diagrams are derived from the same class diagram shown earlier. In other words, each of these object diagrams shows ‘an instance of’ the same class diagram. Which of these class diagrams match the given object diagram?
(a) (b) Explanation: Both class diagrams allow one What does a +/The third compartment represents methods on the class. Attributes and operations can be preceded with a visibility adornment. A plus sign (+) indicates public visibility. A minus sign (-) denotes private visibility.
What is diamond symbol in UML?It signifies aggregation. From wikipedia: In UML, it is graphically represented as a hollow diamond shape on the containing class end of the tree with a single line that connects the contained class to the containing class.
What are the symbols used in the UML class diagram?Pre-drawn UML class diagram symbols represent class, template class, object, item, package, interface, dependency, composition, and association, etc. These symbols help create accurate diagrams and documentation. UML class diagram templates offer you many useful shapes.
How do you represent an interface in UML class diagram?In UML 1.4 interface was formally equivalent to an abstract class with no attributes and no methods and only abstract operations. An interface may be shown using a rectangle symbol with the keyword «interface» preceding the name.
|