Professional Documents
Culture Documents
Laboratory # 03
3/18/2021
UET TAXILA
Engr. Sidra Shafi
Aggregation:
Sometimes a class consists of a number of component classes. This is a special type of relationship
called an aggregation. The components and the class they constitute are in a part-whole association.
For example, home computer system is an aggregation that consists of a CPU box, a keyboard, a
mouse, a monitor, a CD-ROM drive, one or more hard drives, a modem, a disk drive, a printer,
and possibly some speakers. Along with the drives, the CPU box holds RAM, a graphics card, and
a sound card (and probably some other items). You represent an aggregation as a hierarchy with
the "whole" class (for instance, the computer system) at the top and the components below. A line
joins a whole to a component, with an open diamond on the line near the whole. Figure1 shows
the computer system as an aggregation.
Figure 1: An aggregation (part-whole) association is represented by a line between the component and the
whole with an open diamond adjoining the whole.
Sometimes the set of possible components in an aggregation falls into an Or relationship. In some
restaurants, a meal consists of soup or salad, a main course, and a dessert. To model this, you
would use a constraint—the word or within curly brackets on a dotted line that connects the two
part-whole lines, as in Figure 2.
Figure 2: You can place a constraint on an aggregation to show that one component or another is part of the
whole.
Consistency in Constraints
Note the consistency between the use of {or} in Figure 2 (which shows a constraint on an
aggregation) and the previous use of {or} (which shows constraints on association.
Composites:
A composite is a strong type of aggregation. Each component in a composite can belong to just
one whole. The components of a coffee table—the tabletop and the legs—make up a composite.
The symbol for a composite is the same as the symbol for an aggregation except the diamond is
filled, as shown in Figure 3.
Figure 3: In a composite, each component belongs to exactly one whole. A closed diamond represents this
relationship.
The composite is one way to show the components of a class. If you want to give the sense of
showing the class's internal structure, you can go a step further with the UML 2.0 composite
structure diagram.
For example. Suppose you're creating a model of a shirt. Figure 4 shows the shirt as a large class
rectangle with its components nested inside. The nested diagram shows how the components of
the shirt relate to one another.
Figure 4: A composite structure diagram shows the components of a class as a diagram nested inside a large
class rectangle.
The composite structure diagram focuses attention on the shirt and its internal components.
An example will help clarify the interface concept. Every time you use a washing machine, you
don't rip it apart to get to the underlying circuitry so that you can turn it on and set the time
parameters. You don't get into the plumbing to start and stop the water flow. Instead, you get the
washing machine to perform those operations by turning a control knob, shown in Figure 5. As a
Figure 5: The control knob, an interface to a washing machine, allows you to get the washing machine to
carry out some of the washing machine's operations.
The control knob is the washing machine's interface. What operations does the control knob have?
The control knob can close a connection or break a connection, and it can turn clockwise or
counterclockwise by some number of degrees. The control knob's operations are, in a sense,
abstract. Closing or breaking a connection, turning clockwise or counterclockwise—these don't
accomplish anything of value unless the control knob is attached to something. In this case it's
attached to a washing machine. It's almost as if the washing machine makes the control knob's
operations "real" by translating In UML speak, we'd say that the washing machine guarantees that
part of its behavior will "realize" the control knob's behavior. For this reason, the relationship
between a class and its interface is called realization. Why "part of its behavior"? Because it's not
the case that all of the washing machine's operations have to do with control knobs. Some
operations, like acceptClothes() and acceptDetergent(), are accessible via the washing machine's
drum.
Throughout all this, you might have noticed numerous references to an interface's operations, but
nothing about its attributes. That's because as far as we're concerned, it doesn't have any. Yes, a
control knob has a radius and thickness, and perhaps attributes like make and model. The point is
that we don't care about them. When it comes to interfaces, all we are concerned with are their
operations.
You model an interface the same way you model a class, with a rectangle icon. The difference is
that this icon has no attributes. You'll recall that you can elide the attributes out of the
representation of a class. How then do you distinguish between an interface and a class that just
doesn't show its attributes? One way is to add the keyword «interface» above the name of the
interface in the rectangle. Another is to put the letter I at the beginning of the name of any interface.
The symbol for the realization relationship between a class and its interface looks like the symbol
for inheritance, except the line to the open triangle is dashed instead of solid.
Another (elided) way to represent a class and an interface is with a small circle connected by a line to the
class, as in Figure 7. (This is sometimes called a lollipop diagram)
Inheritance Versus Realization and the notation for realization, you might take a moment to
consider these two. Think of inheritance as the relationship between a parent and a child: The
parent passes on physical attributes (eye color, hair color, and so on) to the child, and the child
also takes on behaviors from the parent. Think of realization as something like the relationship
between a teacher and a student: The teacher doesn't pass on any physical attributes to the
student, but the student learns behaviors and procedures from the teacher. The student might reuse
those behaviors to accomplish his or her own goals.
Note: A class can realize more than one interface, and an interface can be realized by more
than one class.
Figure 8: To model interaction with a class through its interface, use a dependency symbol.
Port: Think of your mouse as an interface to your computer. You can do a couple of things with
it—point and click (and roll that little wheel in the middle, if you have that kind of mouse). By
themselves these operations are worthless until your computer "realizes" them. That is, you can
use these operations to locate the cursor and to select items. How does the mouse connect to your
computer? Follow the cable from the mouse to the back of your computer and you'll see a port—
an access point that the mouse plugs into. Of course, your computer also has a serial port, a
parallel port, and one or more USB ports. These ports are the points through which the computer
interacts with its environment. UML 2.0 provides a symbol that models these interaction points.
As Figure 10 shows, the port symbol is a small square on the border of the class icon, and the
square is connected to the interface.
Figure 10: UML 2.0's symbol for the port shows the point through which a class interacts with its
environment.
Visibility:
Figure 11: Public and private operations in a television, and public and protected operations in an
automobile.
Scope:
Scope is another concept relevant to attributes and operations and how they relate across a system.
Two kinds of scope are possible. In instance scope, each instance of a class has its own value for
the attribute or operation. In classifier scope, only one value of the attribute or operation exists
across all instances of the class. A classifier-scoped attribute or operation appears with its name
underlined. All other normal features are treated as instanced scope. This type of scoping is usually
used when a specified group of instances (and no others) has to share the exact values of a private
attribute. Instance scoping is by far the more common type of scope.
Interface: An interface specifies externally visible operations of a class, component, or other classifier
(including subsystems) without specification of internal structure.
Steps:
2. And click at the position where interface will be placed in the main window. Then interface
quick dialog is opened. Enter the interface name at the quick dialog. Press Enter key. Then
the result is as follows.
2. Drag from one (Class, Port, Part, Package, Subsystem) and drop to interface in the main
window. Then requiring interface relationship is created as follows.
Realization:
A realization signifies that a relationship exists between a set of elements that form a specification
(the client) and another set of elements that form the implementation (the supplier).
To create target interface element of selected element, use shortcut creation syntax.
1. Double-click to popup quick dialog. At the quick dialog, enter name of interface elements
of selected element after "-@" string and separate names with ",".
2. And click the class where the port will be contained in the main window.
Visibility Button:
Element visibility can be selected from Public, Protected, Private, and Package.
Double-click on any attribute in a class. ON attribute’s left a symbol will be shown, click on it, a list
will appear, from this list you can change the visibility of attributes. In the same way, you can change
the visibility of operations in a class. In class Student shown below, I have applied protected visibility
on rollno attribute, and private visibility on name attribute. By default, the visibility of attributes and
operations is public.
• Class
• Interface
• Port
• Part
• Dependency
• Connector
Part:
A part is a diagram element that represents a set of one or more instances that a containing
structured classifier owns. A part describes the role of an instance in a classifier. You can create
parts in the structure compartment of a classifier, and in several UML diagrams such as composite
structure, class, object, component, deployment, and package diagrams.
Example:
You use a collaboration when you want to define only the roles and connections that are required
to accomplish a specific goal of the collaboration.
For example, the goal of a collaboration can be to define the roles or the components of a classifier.
By isolating the primary roles, a collaboration simplifes the structure and clarifies behavior in a
model.
1. select package in the [model explorer], right-click, and select [Add] ->
[Collaboration] popup menu.
2. Then collaboration is created under the package in the [model explorer]. Enter the
collaboration name.
2. Drag from one part and drop to the other part in the [main window].
Line Style:
Line type of elements such as Association, Dependency and Generalization are expressed by either of
the following two types of line styles.
• Rectilinear: Line always changes in 90-degree angles.
• Oblique: Line changes at any angle.
Right click on any line between elements -> Select Format -> Line Style -> Select line-style as
Rectangular. The result will be as follows.
Lab tasks
Scenario:
A studio uses a Player. DVDPlayer and CDPlayer must implement the operations of Player
Interface. Recorder is inherited from Player. It is necessary for TapePlayer to implement the
operation of Recorder as well as its four inherited operations.
Task 1: Marks: 5
Draw a class diagram which consists of classes and interfaces. Identify the operations of
interfaces Player and Record.
Task 2: Marks: 5
Draw ball and socket diagram.
*****************