SDA Lab 2 2k23 Part 2
SDA Lab 2 2k23 Part 2
Laboratory # 02
1/27/2025
UET TAXILA
Engr. Sidra Shafi
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. Pascal casing is
used for giving names to classes.
Attributes:
An attribute is a property of a 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, camel casing is used.
The list of attribute names begins below a line separating them from the classname.
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.
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.
Camel Casing is used for creating names for operations. The list of operations begins below a line
that separates the operations from the attributes.
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.
With PascalCase, the first letter of every word in the identifier is upper case. With camelCase,
the first letter of the first word in the identifier is lower case, while the first letter of every
subsequent word is uppercase.
Associations
When classes are connected together conceptually, that connection is called an association.
This kind of relationship represents static relationships between classes A and B. For example, an
employee works for an organization.
In this example, the relationship between student and college is shown which is studies.
A constraint specifies conditions that must be held true for the model to be well-formed.A
constraint is rendered as a string enclosed by brackets and placed near the associated element.
If you want to specify your semantics more precisely, you can use the UML’s Object Constraint
Language (OCL) as shown in the following class diagram:
Association classes allow you to add attributes, operations, and other features to associations, as
shown in Figure.
Link:
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.
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,
Generalization:
Generalization is a mechanism for combining similar classes of objects into a single, more general
class. Generalization identifies commonalities among a set of entities. The commonality may be
of attributes, behavior, or both. In other words, a superclass has the most general attributes,
operations, and relationships that may be shared with subclasses. A subclass may have more
specialized attributes and operations.
Specialization is the reverse process of Generalization means creating new sub-classes from an
existing class.
For Example, a Bank Account is of two types - Savings Account and Credit Card Account.
Savings Account and Credit Card Account inherit the common/ generalized properties like
Account Number, Account Balance, etc. from a Bank Account and also have their specialized
properties like unsettled payment etc.
Dependency: In a different kind of relationship, one class uses another. This is called a
dependency.
Adding Attributes:
Adding qualifier:
Right click on association-> Collection Editor -> Qualifier
Directed Association:
Select directed association symbol from toolbox. Drag and drop between two elements in arrow
direction.
Drag from one associated class and drop to another in the main window.
Composition:
The composition is a subset of aggregation. It portrays the dependency between the parent and its
child, which means if one part is deleted, then the other part also gets discarded. It represents a
whole-part relationship.
Drag from one contained class and drop to another container class.
Dependency:
It indicates a situation in which a change to the target element may require a change to the source
element in the dependency.
*******************