You are on page 1of 17

Software Architecture and Design

Laboratory # 03

3/18/2021
UET TAXILA
Engr. Sidra Shafi

CLO Learning Outcomes Assessment Item BT Level PLO


No.
1 Construct the experiments / projects Lab Task, Mid Exam,
of varying complexities. Final Exam, Quiz,
P2 3
Assignment, Semester
Project
2 Use modern tool and languages. Lab Task, Semester
P2 5
Project
3 Demonstrate an original solution of Lab Task, Semester
A2 8
problem under discussion. Project
4 Work individually as well as in teams Lab Task, Semester A2 9
Project
Understanding Aggregations, Composites, Interfaces, and
Realizations
Statement Purpose:
After this Lab, students will be able to understand:
• Aggregation, Composites, Interfaces, And Realizations,
• How to model classes that consist of other classes
• How to model interfaces and their connections with classes
• The concept of visibility and scope.

UML Tool: Star UML version 5.


Download Link: https://staruml.informer.com/versions/

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.

4th Semester UET TAXILA


Constraints on Aggregations

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.

4th Semester UET TAXILA


Composite Structure Diagram:

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.

Interfaces and Realizations:


Encapsulation is the idea that an object hides its operations from other objects. When you lock
your car, for example, the car doesn't show you how it performs the lockup operation. When you
change channels on your TV, your TV doesn't let you see how it's done. If these operations are
hidden, how do you get the car or the TV to perform them? The car and the TV both receive a
message (a request to perform an operation) through an interface. An interface is a set of
operations that specifies some aspect of a class's behavior, and it's a set of operations a class
presents to other classes.

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

4th Semester UET TAXILA


result of manipulating the knob, you can turn the machine on or off or set some parameter related
to washing your clothes.

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.

Figure 6 shows the realization between WashingMachine and Control Knob.

4th Semester UET TAXILA


Figure 6. An interface is a collection of operations that a class carries out. A class is related to an interface
via realization, indicated by a dashed line with an open triangle that points to the interface.

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)

Figure 7: The elided way of representing a class realizing an interface.

Inheritance versus Realization:

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.

4th Semester UET TAXILA


Figure 9: UML 2.0's "ball-and-socket" notation for modeling interaction through an elided interface
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:

Closely related to interfaces and realizations is the concept of visibility.


Visibility applies to attributes or operations and specifies the extent to which other classes can use
a given class's attributes or operations (or an interface's operations). Four levels of visibility are
possible. At the public level, usability extends to other classes. At the protected level, usability is
open only to classes that inherit from the original class. At the private level, only the original class
can use the attribute or operation. At the Package level, all classes in Package can use an attribute
or an operation
Realization implies that the public level applies to every operation in an interface. Shielding the
operations via either of the other levels would make no sense, as an interface is intended for
realization by a multitude of classes.

4th Semester UET TAXILA


To denote the public level, precede the attribute or operation with a "+"; to denote the protected
level, precede it with a "#"; and to denote private, precede it with a "–". ~ is used to show package
level. Figure 11 shows the aforementioned public, protected, and private operations in a television
and in an automobile.

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.

Modeling in Star UML

Interface: An interface specifies externally visible operations of a class, component, or other classifier
(including subsystems) without specification of internal structure.

An interface is represented using a class icon with the <<interface>> stereotype.

4th Semester UET TAXILA


UML's realization arrow indicates that a class implements or realizes one or more interfaces:

Steps:

1. Click on interface symbol in toolbox,

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.

Steps for creating providing relationship

1. To create providing relationship, Click Toolbox -> Realization symbol.

4th Semester UET TAXILA


2. Drag from one (Class, Port, Part, Package, Subsystem) and drop to interface in the main
window. Then providing interface relationship is created as follows.

Steps for creating requiring relationship

1. To create requiring relationship, Click Toolbox -> Dependency symbol.

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).

Steps for creating realization

Procedure for creating realization target element of selected element

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 ",".

4th Semester UET TAXILA


2. Press [Enter] key and interface elements of selected element are created and arranged
automatically.

Steps for creating port:

1. To create port, Click Toolbox -> Port button.

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.

4th Semester UET TAXILA


Modeling with Composite Structure Diagram in Star UML:

The following elements are available in a composite structure diagram.

• 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:

4th Semester UET TAXILA


In this example the Wheels and the Engine are the Parts of the Collaboration and the FrontAxle
and the RearAxle are the Connectors. The Car is the Composite Structure that shows the parts and
the connections between the parts.

A collaboration describes a structure of collaborating parts (roles).

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.

Steps for creating part:

To create part in composite structure diagram

1. Click [Toolbox] -> [Composite Structure] -> [Part] button


2. Click a class where the part will be contained in the [main window].
3. Then a part is created in the class.

4th Semester UET TAXILA


Steps for creating collaboration

To create collaboration in composite structure diagram,

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.

3. And drag the collaboration and drop on the [main window]

4th Semester UET TAXILA


4. Then the collaboration is placed on the diagram.

Steps for creating connector:

To create connector in composite structure diagram,

1. Click [Toolbox] -> [Composite Structure] -> [Connector] button.

2. Drag from one part and drop to the other part in the [main window].

3. Then connector between two parts is created finally.

4th Semester UET TAXILA


Font:
Text font shape, color, size, etc. for elements can be changed.
Right click on an element -> Select Format -> Font -> Select Red Color. The result will be as follows.

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.

Previously, we have used Oblique line-style in labs.

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.

4th Semester UET TAXILA


Scenario:

A database implements the operations of a databaseAccess Interface. A database query


depends on database Acess to execute. Identify the operations of Database and attributes of
database query.

Task 2: Marks: 5
Draw ball and socket diagram.

*****************

4th Semester UET TAXILA

You might also like