You are on page 1of 35

SOFTWARE REQUIREMENT

ENGINEERING

Experiment 3
Working With Object Orientation, Class diagrams and
relationship among Classes

CLO 1 : Construct the experiments/projects of varying complexities.

CLO 2: Use modern tools and languages.

CLO 3: Demonstrate an original solution of problem under discussion.

CLO 4: Work individually as well as in teams.


Purpose:

This experiment provides an introduction to Unified Modeling Language. Student will


get basic introduction of the diagrams available for system modeling. StarUML
modelling tool will also be introduced in this lab.

Objectives:

At the end of this experiment you will

1. How to model a class

2. How to show a class's attributes and features

3. How to discover classes

4. Use of StarUML in visualizing Classes

5. How to model the connections among classes

6. How to visualize class-subclass relationships

7. How to show dependencies among classes

8. Relations in StarUML

Equipment and Components:

1. StarUML v4.1.2
2. Microsoft Visio Professional 2019
1-Class
A class is a category or group of things that have the same attributes and the same behaviors.
1.1 Visualizing a Class
A rectangle is the icon that represents a class in the UML. The name of the class is, by
convention, a word with an initial uppercase letter. It appears near the top of the rectangle. If your
class has a two-word name, join the two words together and capitalize the first letter of the
second word (as in WashingMachine in Fig 1).

Fig 1:The UML class icon


1.2 Attributes
An attribute is a property of a class. It describes a range of values that the property may hold in
objects (that is, in instances) of that class. A class may have zero or more attributes.
By convention, a one-word attribute name is written in lowercase letters. If the name consists of
more than one word, the words are joined and each word other than the first word begins with an
uppercase letter. The list of attribute names begins below a line separating them from the
classname, as Fig 2 shows.

Fig 2: Class and its attributes


Every object of the class has a specific value for every attribute. Fig 3 presents an example. Note
that an object's name begins with a lowercase letter, precedes a colon that precedes the classname,
and the whole name is underlined.

Fig 3: An object has a specific value for every one of its class's attributes

The UML gives you the option of indicating additional information for attributes. In the icon for
the class, you can specify a type for each attribute's value. Possible types include string, floating-
point number, integer, and Boolean (and other enumerated types). To indicate a type, use a colon
to separate the attribute name from the type. You can also indicate a default value for an attribute.
Fig 4 shows these ways of specifying attributes.

Fig 4: An attribute can show its type as well as a default value


1.3 Operations
An operation is something a class can do, and hence it is something that you (or another class)
can ask the class to do. Like an attribute name, an operation's name is all in lowercase
if it's one word. If the name consists of more than one word, join the words and begin all words
after the first with an uppercase letter. The list of operations begins below a line that
separates the operations from the attributes, as in Fig 5.
Fig 5: The list of a class's operations appears below a line that separates them from the class's
attributes.
Just as you can indicate additional information for attributes, you can indicate additional
information for operations. In the parentheses that follow an operation name, you can show the
parameter that the operation works on, along with that parameter's type. One kind of operation,
the function, returns a value after it finishes doing its work. For a function, you can show the
value it returns and that value's type.These pieces of information about an operation are called the
operation's signature. Fig 6 shows a couple of ways to represent the signature. The first two
operations show the type of the parameter. The third and fourth show the type of the return
value.

Fig 6: Signatures for operations


 In UML, a multiword classname has initial capital letters for all the words and
eliminates white space between each word (for example, WashingMachine).
 Attribute names and operation-names follow the same convention, but the first
letter of the first word isn’t capitalized (for example, acceptClothes ()) .

2- Associations:
When classes are connected together conceptually, that connection is called an association.
Let's examine one—the association between a player and a team. You can characterize this
association with the phrase "a player plays on a team." You visualize the association as a line
connecting the two classes, with the name of the association ("Plays on") just above the line. You
show how to read the relationship with a filled triangle pointing in the appropriate direction.
Figure 7 shows how to visualize the Plays on association between the player and the team.

Figure 7: An association between a player and a team.

When one class associates with another, each one usually plays a role within that association.
You can show each class's role by writing it near the line next to the class. In the association
between a player and a team, if the team is professional, it's an employer and the player is an
employee. Figure 8 shows how to represent these roles.

Figure 8. In an association, each class typically plays a role. You can represent those roles on the diagram.

You can imagine an association that you could read in the other direction: A team employs
players. You can show both associations in the same diagram, with a filled triangle indicating
how to read each association, as in Figure 9.

Figure 9: Two associations between classes can appear on the same diagram.
Associations may be more complex than just one class connected to another. Several classes can
connect to one class. If you consider guards, forwards, and centers, and their associations with the
Team class, you'll have the diagram in Figure 10.
Figure 10: Several classes can associate with a particular class.

1.4 Constraints on Associations


Sometimes an association between two classes has to follow a rule. You indicate that rule by
putting a constraint near the association line. For example, a Bank Teller serves a Customer, but
each Customer is served in the order in which he or she appears in line. You capture this in the
model by putting the word ordered inside curly brackets (to indicate the constraint) near the
Customer class, as in Figure 11.

Figure 11.You can place a constraint on an association. In this example, the Serves association is
constrained to have the Bank Teller serve the Customer in order.

Another type of constraint is the Or relationship, signified by {or} on a dashed line that connects
two association lines. Figure 12 models a high school student choosing either an academic course
of study or a commercial one.
Figure 12. The Or relationship between two associations is a constraint.

2.1 - Association Classes


An association can have attributes and operations, just like a class. In fact, when this is the case,
you have an association class. You visualize an association class the same way you show a
regular class, and you use a dashed line to connect it to the association line. An association class
can have associations to other classes. Figure 13 shows an association class for the Plays on
association between a player and a team. The association class, Contract, is associated with the
GeneralManager class.

Figure 13. An association class models an association’s attributes and operations. It’s connected to
an association via dashed line and can associate with another class.

2.2 Links
Just as an object is an instance of a class, an association has instances as well. If you imagine a
specific player who plays for a specific team, the Plays on relationship is called a link, and you
represent it as a line connecting two objects. Just as you would underline the name of an object,
you underline the name of a link, as in Figure 14.
Figure 14. A link is an instance of an association. It connects objects rather than classes. In a link,
you underline the name of the link, just as you underline the name of an object.

2.3 Multiplicity
The association drawn so far between Player and Team suggests that the two classes are in a one-
to-one relationship. Common sense tells you that this isn't the case, however. A basketball team
has five players (not counting substitutes). The Has association must take this into account. In the
other direction, a player can play for just one team, and the Plays on association must account for
that. These specifications are examples of multiplicity—the number of objects from one class
that relate with a single object in an associated class. To represent these numbers in the diagram,
you place them near the appropriate class, as in Figure 15. (The numbers can go either above or
below the association line.)

Figure 15. Multiplicity denotes the number of objects of one class that can relate to one object of an
associated class.

The multiplicity in this example is not the only type. A variety of multiplicities are possible (a
multiplicity of multiplicities, so to speak). One class can relate to another in a 1-to-1, 1-to many,
1-to-1 or more, 1-to-0 or one, 1-to-a bounded interval (for example, 1-to-5 through 10), 1-to-
exactly n (as in this example), or 1-to-a set of choices (for example, one-to-nine or ten).
The UML uses an asterisk (*) to represent more and to represent many. In one context Or is
represented by two dots, as in 1..* ("one or more"). In another context, Or is represented by a
comma, as in 5,10 ("5 or 10").

Figure 16 shows how to visualize possible multiplicities. (Note that the phrase at the right of
each multiplicity in Figure 16 isn't part of the UML. It's just a label I added to help clarify things.)

Figure 16. Possible multiplicities and how to represent them in the UML.

2.4 Qualified Associations


When an association's multiplicity is one-to-many, a particular challenge often arises: lookup.
When an object from one class has to choose a particular object from another in order to fulfill a
role in an association, the first class has to rely on a specific attribute to select the correct object.
That attribute is typically an identifier, such as an ID number. For example, a hotel's reservation
list has many reservations, as Figure 17 shows.
Figure 11. A reservation list and its reservations are in a one-to many multiplicity.

Figure 12.The UML notation for a qualifier. The idea is that when you add that little
rectangle, you qualify the association.

When you make a reservation at a hotel, the hotel assigns you a confirmation number. If you call
with questions about the reservation, you have to supply the confirmation number, so that
someone looking through the reservation list can select your reservation.
In the UML, the ID information is called a qualifier. Its symbol is a small rectangle adjoining the
class that has the "one" part in the one-to-many multiplicity. Figure12 shows the representation.
Although the multiplicity between ReservationList and Reservation is one-to-many, the
multiplicity between confirmationNumber and Reservation is one-to-one.

Reflexive Associations
Sometimes, a class is in an association with itself. Referred to as a reflexive association, this can
happen when a class has objects that play a variety of roles. For example, a CarOccupant can be
either a driver or a passenger. In the role of the driver, one CarOccupant drives zero or more
additional CarOccupants who play the role of passenger. You represent this by drawing an
association line from the class rectangle back to the same class rectangle, and on the association
line you indicate the roles, name of the association, direction of the association, and multiplicity
as before. Figure 13 presents this example.
Figure 13. In a reflexive association, you draw the line from the class to itself, and you can
include the roles, association name, direction of the association, and multiplicity.
Inheritance and Generalization
One of the hallmarks of object-orientation is that it captures one of the great common sense
aspects of day-to-day life: If you know something about a category of things, you automatically
know some information you can transfer to other categories. If you know something is an
appliance, you already know it has an on-off switch, a brand name, and a serial number. If you
know something is an animal, you take for granted that it eats, sleeps, has a way of being born,
has a way of getting from one place to another, and probably has a number of other attributes
(and operations) you could list if you thought about it for a few minutes.
Object-orientation refers to this as inheritance. The UML also refers to this as generalization.
One class (the child class or subclass) can inherit attributes and operations from another (the
parent class or superclass). The parent class is more general than the child class.

The inheritance hierarchy doesn't have to end at two levels: A child class can be a parent class for
still another child class. Mammal is a child class of Animal, and Horse is a child class of
Mammal.

In the UML, you represent inheritance with a line that connects the parent class to the child class.
On the part of the line that connects to the parent class, you put an open triangle that points to the
parent class. This type of connection stands for the phrase is a kind of. A Mammal is a kind of
Animal, and a Horse is a kind of Mammal. Figure 14 shows this particular inheritance hierarchy,
along with some additional classes.
Figure 14. An inheritance hierarchy in the animal kingdom

In the figure, note the appearance of the triangle and the lines when more than one child class
inherits from a parent class. Setting the diagram up this way results in a less busy diagram than
showing all the lines and triangles, but the UML doesn't prohibit putting all of them in the
picture. Note also that you don't put the inherited attributes and operations in the subclass
rectangles, as you've already represented them in the superclass. Child classes add to the
attributes and operations they inherit. For example, a Mammal has hair and gives milk, two
attributes not found in the Animal class. A class might have no parents, in which case it's a base
class or root class. A class might have no children, in which case it's a leaf class. If a class has
exactly one parent, it has single inheritance. If a class has more than one parent, it has multiple
inheritance.

Abstract Classes
In the basketball model, the class—Player is useful because it serve as parent class for important
child class. The child classes are important in the model because you'll ultimately want to have
instances of these classes. To develop the model you'll need instances of Guard, Forward, Center,
GameClock, and ShotClock. Player and , however, will not provide any instances for the model.
An object from the Player class would serve no purpose.
Classes like Player are said to be abstract. You indicate an abstract class by writing its name in
italics. Figure 15 shows the abstract class and children.
Figure 15.Inheritance hierarchy with abstract class in the basketball model.

Dependencies
In a different kind of relationship, one class uses another. This is called a dependency. The most
common usage of a dependency is to show that the signature of one class's operation uses another
class.
Suppose you're designing a system that displays corporate forms on-screen so employees can fill
them out. The employee uses a menu to select the form to fill out. In your design, you have a
System class and a Form class. Among its many operations, the System class has
displayForm(f:Form). The form the system displays obviously depends on which form the user
selects. The UML notation for this is a dashed line with an arrowhead pointing at the class
depended on, as in Figure 16.

Figure 16. A dashed line with an arrowhead represents a dependency.


Modeling With StarUML

StarUML™ supports 11 UML diagram types. The user can freely create and manage different
diagrams as needed.

1. After starting SU, a template box titled "New Project by Approach" may be present: if it
is, select "Empty Project" and press "Ok".   It is suggested that you uncheck "Set Default
Approach”.

2. Open a New proect.

3. You will find the following window.


Modeling with Class Diagram

The following elements are available in the class diagram.

 Subsystem
 Package
 Class
 Interface
 Enumeration
 Signal
 Exception
 Port
 Part
 Association
 DirectedAssociation
 Aggregation
 Composition
 Generalization
 Dependency
 Realization
 AssociationClass
 Connector
 Object
 Link

Class
Semantics

A class is the descriptor for a set of objects with similar structure, behavior, and relationships.

Procedure for creating class

In order to create class,

1. Click [Toolbox] -> [Class] -> [Class] button.

2. And click at the position where class will be placed in the [main window].

3. A new class is created on the diagram and class quick dialog is opened.
4. At the quick dialog, enter the class name and press [Enter] key.
Proceudre for adding attribute

There are three method to add attribute to class.

 using quick dialog


 using model in the [main window] or the [model explorer]
 using [collection editor]

In the case of using quick dialog,

1. Double-click class.
2. Press [Add Attribute] button at the quick dialog, and you can add attribute.

In the case of using model,

1. Select class in the [main window] or in the [model explorer].


2. Right-click the selected class, select [Add] -> [Attribute] popup menu, and you can do.

In the last case,


1. Select [Collection Editor...] popup menu.

2. Or click button in [attributes] property on properties window.

3. At [attribute] tab of the [collection editor], you can add attribute by using button.

Proceudre for adding operation

There are three method to add attribute to class.


 using quick dialog
 using model in the [main window] or the [model explorer]
 using [collection editor]

In the case of using quick dialog,

1. Double-click class and class quick dialog is shown.


2. Press [Add Operation] button at the quick dialog, and you can add operation.

In the case of using model, select class in the [main window] or in the [model explorer], right-
click the selected class, select [Add] -> [Operation] popup menu, and you can do.

In the last case,

1. Select [Collection Editor...] popup menu.


2. At [operations] tab of the [collection editor], you can add operation by using button.

Procedure for adding parameter to operation

In order to add parameter to operation,


1. Select operation in the [model explorer], select [Add] -> [Parameter] popup menu,
and new parameter will be added.

2. Or select operation in the [model explorer], select [Collection Editor...] popup menu.
3. Or click button in [Parameters] property on properties window.

4. At the [Parameters] tab of the [collection editor], you can add parameter by using
button.

Association

Semantics

An association is an association among exactly two classifiers (including the possibility of an


association from a classifier to itself).

Procedure for creating association

In order to create association,


1. Click [Toolbox] -> [Class] -> [Association] button.

2. Drag from one associated and drop to another in the [main window].

3. Between two classes, a new association is created as follows.

Procedure for adding qualifier to association

In order to add qualifier to association,


1. Select association's [Collection Editor...] popup menu.

2. Or click button in [End.Qualifiers] property on properties window.


3. At [Qualifiers] tab of the [collection editor], you can add qualifier to the association by using button.

4. The result is as follows.

Procedure for creating multiple classes related to current class at once

If you want to create Dog, Pig, Cat classes related to Me class

1. Double-click Me class or press [Enter] key. At quick dialog, enter as following.


2. Then three classes with association are created as following.

DirectedAssociation

Procedure for creating directed association

Procedure for creating directed association is equal to association's.

1. Click [Toolbox] -> [Class] -> [DirectedAssociation].

2. Drag and drop between two elements in arrow direction.


3. The result is as follows.

Procedure for changing association to directed association

To change association to directed association, click the arrow-opposite-side association end.


At the quick dialog, uncheck navigable and association becomes directed.

Procedure for creating element having directed association by shortcut


creation syntax

In order to create element having directed association, use shortcut creation syntax,

1. Double-click element. At the quick dialog, enter name of elements that have directed association after "->" string
and separate names with ",".
2. Press [Enter] key and multiple elements associated with selected element are created and arranged
automatically.

Aggregation

Semantics

An aggregate is a more specific type of association. The aggregate is signified by a hollow


diamond on the point where the association connects with the classifier (association end).

Procedure for creating aggregate

In order to create aggregation,

1. Click [Toolbox] -> [Class] -> [Aggregation] button.


2. Drag from one associated and drop to another in the [main window].

3. The result is as follows.

Procedure for creating aggregated class by shortcut creation syntax

In order to create class aggregated to selected class, use shortcut creation syntax.

1. Double-click to popup quick dialog. At the quick dialog, enter name of class aggregated to current class after
"<>-" string  and separate names with ",".

2. Press [Enter] key and classes aggregated to selected class are created and arranged automatically.
Composition

Semantics

A composite is a more specific type of association. The composite is signified by a filled


diamond on the point where the association connects with the classifier (association end).

Procedure for creating composition

In order to create composition,

1. Click [Toolbox] -> [Class] -> [Composition] button.

2. Drag from one class and drop to another class composed in the [main window].

3. Between two classes, a new composition relationship is created as follows.


Procedure for creating composing class by shortcut creation syntax

In order to create class composing selected class, use shortcut creation syntax.

1. Double-click to popup quick dialog. At the quick dialog, enter name of class composing selected class after
"<*>-" string  and separate names with ",".

2. Press [Enter] key and classes composing selected class are created and arranged automatically.

Generalization

Semantics

Generalization is the taxonomic relationship between a more general element (the parent)
and a more specific element (the child) that is fully consistent with the first element and that
adds additional information. It is used for classes, packages, usecases, and other elements.

Procedure for creating generalization

In order to create generalization,

1. Click [Toolbox] -> [Class] -> [Generalization] button.


2. Drag from child element and drop to parent element in the [main window].

3. Then a new generalization is created.

Procedure for creating multiple children classes at once.

In order to create multiple children classes inheriting selected class at once, use shortcut
creation syntax.

1. Double-click to popup quick dialog. At the quick dialog, enter name of class inheriting selected class after "<="
string  and separate names with ",".

2. The children classes are created below selected class and arranged automatically.

3. From tool box select association class and connect it to association line.
Procedure for creating multiple parent classes at once

In order to create multiple parent classes of selected class at once, use shortcut creation
syntax.

1. Double-click to popup quick dialog. At the quick dialog, enter name of parent classes of  selected class after "=>"
string  and separate names with ",".

2. The parent classes are created above selected class and arranged automatically.

Dependency

Semantics

A dependency indicates a semantic relationship between two model elements (or two sets of
model elements). It relates the model elements themselves and does not require a set of
instances for its meaning. It indicates a situation in which a change to the target element
may require a change to the source element in the dependency.

Procedure for creating dependency

In order to create dependency,

1. Click [Toolbox] -> [Class] -> [Dependency] button.


2. Drag and drop between elements in the [main window] in depending direction.

3. A new dependency between two classes is created.

Procedure for dependent element by shortcut creation syntax

In order to create element depending by selected element, use shortcut creation syntax.

1. Double-click to popup quick dialog. At the quick dialog, enter name of dependent elements by selected element
after "-->" string  and separate names with ",".

2. Press [Enter] key and dependent elements by selected class are created and arranged automatically.
Lab Tasks
1-Create a class of washing machine and add Attribute, operations and parameters to that class
using StarUML.

2- You have been asked to design a Student Registration System to replace the university’s legacy
system. The system will allow students to register for courses and view grade reports.
Each student has access to his or her course and grade information only and must be
authenticated prior to viewing or updating the information.
A course instructor will use the system to view the list of courses he or she is assigned for a
given semester or has taught previously, view the list of students registered for the course(s)
he or she is teaching, and record final grades for each student in the course(s). Instructors
must also be authenticated prior to viewing or updating any information.
Follow the process documented below to design the Student Registration System.
Analysis and Design Process
1. Analyze the written requirements.
a. Identify the nouns. Highlight or list the nouns your find in the requirements.
b. Identify the verbs. Highlight or list the verbs you find in the requirements.
2. Draw the Class Diagram for the system.
a. Draw the nouns as classes.
b. Draw the verbs as associations/relationships between classes.
c. Assign a multiplicity to each association (i.e., one-to-one, one-to-many, many-to-many)
3. Update the Class Diagram with class attributes.
4. Update the Class Diagram with class methods.

You might also like