You are on page 1of 26

MIRPUR UNIVERSITY OF SCIENCE AND TECHNOLOGY

DEPARTMENT OF SOFTWARE ENGINEERING

Software Construction & Development 1


Software Construction & Development
(Lecture # 2)
UML Class Modeling

Huma Sheraz
(Lecturer)
LECTURE CONTENTS

1. Static Object Modeling

2. Class Diagram

3. Domain Classes vs Design Classes

4. Composition Relationship

5. Aggregation Relationship

Software Construction & Development 3


STATIC OBJECT MODELING
• Focus is on the static structure of the system.
• Explore the packages and components in a white-box fashion.
• In particular, a static model defines the classes in the system, the attributes of the
classes, the relationships between classes, and the operations of each class
• UML Notation: Class Diagram

Software Construction & Development 4


THE UML CLASS DIAGRAM

• A class diagram describes the static view of a system in terms of classes and
relationships among the classes

• The UML includes class diagrams to illustrate classes and their associations.

Software Construction & Development 5


CLASS DIAGRAMS

• Class diagrams are used when developing an object-oriented system model to


show the classes in a system and the associations between these classes
• An association is a link between classes that indicates that there is some
relationship between these classes
• When you are developing models during the early stages of the SE process,
objects represent something in the real world, such as a patient, a
prescription, doctor, etc

Software Construction & Development 6


CLASS DIAGRAMS
• Each class is represented by a rectangle subdivided into three
compartments
• Name
• Attributes
• Operations
• Modifiers are used to indicate visibility of attributes and operations.
• ‘+’ is used to denote Public visibility (everyone)
• ‘#’ is used to denote Protected visibility (friends and derived)
• ‘-’ is used to denote Private visibility (no one)
• By default, attributes are hidden and operations are visible

Software Construction & Development 7


AN EXAMPLE OF CLASS

Name
Account_Name
- Custom_Name
Attributes
- Balance
+AddFunds( ) Operations
+WithDraw( )
+Transfer( )

Software Construction & Development 8


NOTATION OF CLASS DIAGRAM: GENERALIZATION

Supertype Example: Customer

Regular Loyalty
Customer Customer

Subtype1 Subtype2
or: Customer
Generalization expresses a
relationship among related
classes. It is a class that
includes its subclasses.
Regular Loyalty
Customer Customer
Software Construction & Development 9
NOTATION OF CLASS DIAGRAM :COMPOSITION
COMPOSITION
Whole Class
Composition: Expresses a relationship
Class W
among instances of related classes. It
is a specific kind of Whole-Part
relationship.
Class P1 Class P2
•Composition should be used to
express a relationship where the
Part Classes
behavior of Part instances is undefined
Example
without being related to an instance of
the Whole.
Automobile

•And, conversely, the behavior of the


Whole is incomplete if one or more of
Engine Gear the Part instances are undefined.

Software Construction & Development 10


NOTATION OF CLASS DIAGRAM :AGGREGATION

Container Class
Class C Aggregation: Expresses a relationship among
AGGREGATION instances of related classes. It is a specific kind
of Container-Containee relationship.
Class E1 Class E2
Aggregation is an appropriate relationship
Containee Classes where the Container and its Containees can be
manipulated independently.

Example
Bag

Apples Milk

Software Construction & Development 11


AGGREGATION VS COMPOSITION
Composition is really a strong form of aggregation
• Components cannot exist independent of their owner; both have
coincident lifetimes
• Components live or die with their owner
e.g. (1)Each car has an engine that cannot be shared with other cars
(2) If the polygon is destroyed, so are the points
Aggregations may form "part of" the aggregate, but may not
be essential to it. They may also exist independent of the
aggregate. Less rigorous than a composition
e.g. (1)Apples may exist independent of the bag
(2)An order is made up of several products, but the
products are still there even if an order is cancelled

Software Construction & Development 12


CLASS MODEL : GENERALIZATION
(INHERITANCE)
• In object-oriented languages, such as C++ and Java, generalization is
implemented using the class inheritance mechanisms built into the language.
• In a generalization, the attributes and operations associated with higher-level
classes are also associated with the lower-level classes.
• The lower-level classes are subclasses inherit the attributes and operations from
their super-classes.
• These lower-level classes then add more specific attributes and operations.

Software Construction & Development 13


A GENERALIZATION HIERARCHY

Software Construction & Development 14


A GENERALIZATION HIERARCHYWITH ADDED
DETAIL

Software Construction & Development 15


NOTE CAN ALSO BE USED
• Note symbols can be used on any UML diagram, but are
especially common on class diagrams
• A UML note symbol is displayed as a dog-eared rectangle
with a dashed line to the annotated element

Register
«method»
// pseudo-code or a specific language is OK ...
public void enterItem( id, qty )
{ endSale()
ProductDescription desc = catalog.getProductDescription(id); enterItem(id, qty)
sale.makeLineItem(desc, qty); makeNewSale()
} makePayment(cashTendered)

Software Construction & Development 16


SHOWING DEPENDENCY

•The UML includes a general dependency relationship that indicates that a client
element (classes) has knowledge of another supplier element (other class) and that
a change in the supplier could affect the client.
•Dependency is illustrated with a dashed arrow line from the client to supplier.
•There are many kinds of dependency; here are some common types:
• Having an attribute of the supplier type
•Sending a message to a supplier
•Receiving a parameter of the supplier type

Software Construction & Development 17


SHOWING DEPENDENCY

Software Construction & Development 18


OPTIONAL DEPENDENCY LABLES

Software Construction & Development 19


CONSTRAINTS

three ways to show UML constraints

Stack

size : Integer { size >= 0 }

push( element ) { post condition: new size = old size + 1 }


pop() : Object

{
post condition: new size = old size – 1
}

Software Construction & Development 20


Constraints

Software Construction & Development 21


QUALIFIED ASSOCIATION
• A qualified association has a qualifier that is used to select an object from a larger set
of related objects, based upon the qualifier key
• For example, if a ProductCatalog contains many ProductDescriptions, and each one
can be selected by an itemID, then the UML notation in Figure can be used to depict this

(a) Product Contains Product


Catalog Description
1 1..*

1 1
Product Contains Product
(b) itemID
Catalog Description

qualifier multiplicity reduced to 1

Software Construction & Development 22


ASSOCIATION CLASS
• An association class allows you treat an association itself as a class, and model it with
attributes, operations, and other features
•For example, if a Company employs many Persons, modeled with an Employs
association, you can model the association itself as the Employment class, with attributes
such as startDate
•In the UML, it is illustrated with a dashed line from the association to the association
class.
Employs
Company * * Person

a person may have Employment


employment with several
companies salary
startDate

Software Construction & Development 23


CLASS MODEL EXAMPLE 2

Software Construction & Development 24


REFERENCES

• Software Engineering: A Practitioner’s Approach, Roger S. Pressman,


Bruce R. Maxim, 8th Ed, McGraw-Hill Education, 2015.
• Object-Oriented Analysis, Design and Implementation, Brahma
Dathan, Sarnath Ramnath, 2nd Ed, Universities Press, 2014

Software Construction & Development 25


THANKS

You might also like