APT 2080: INTRODUCTION TO
SOFTWARE ENGINEERING
Structural Modelling using Class Diagrams
Introduction
• Towards the end of the analysis phase, functional models
representing how the system will behave were created
• During the design phase, we need to understand how the
system will be organized
• This organization defines the structure of the system
during the design of the system architecture
Structural Models
• A structural model is a formal way of representing the
organization of ideas or concepts in an information system
• Structural models display the organization of a system in terms
of components making up the system and their relationships.
• A structural model can be ‘abstract’ (it is not tied to any specific
implementation) or ‘concrete’ (it is tied to a specific
implementation) depending on what is needed
• Structural modelling helps create a vocabulary that can be used
by the analyst and the users to communicate effectively
• Structural models represent the things, ideas, or concepts
contained in the domain of the problem
• Structural models also represent the relationships among the
things, ideas, or concepts
Structural Diagrams (Models)
• There are a number of Structural UML diagrams
or models
• Below are UML structural models:
– Class diagrams
– Object diagrams
– Deployment diagrams
– Package diagrams
– Composite structure diagram
– Component diagram
Class Diagram
• A Class Diagram is a diagram describing the structure of a system and
shows the system's;
• Classes
• Attributes
• Operations/ Methods
• Relationships among the classes
• Class diagrams are used when developing an object-oriented system
model to show the classes in the system and the associations between
these them.
• They are used to describe the types of objects in a system and their
relationships
• Class diagrams are composed of classes, attributes, methods,
associations, messages and multiplicity
Essential Elements of a UML Class Diagram
• Class
• Attributes
• Operations
• Relationships
• Associations
• Generalization
• Realization
• Dependency
• Constraint Rules and Notes
Class
• Describes a set of objects having similar:
• Attributes (status)
• Operations (behavior)
• Relationships with other classes
• Attributes and operations may have their visibility marked as:
• "+" for public
• "#" for protected
• "−" for private Class Name
Window
• "~" for package
size: Size
Attributes visibility: boolean
display()
Operations hide()
Class Symbols
Class Symbols (2)
Associations
• An association between two classes indicates that objects at one
end of an association “recognize” objects at the other end and may
send messages to them.
• Instance of one class must know about the other in order to
perform its work
• Example: “An Employee works for a Company”
Employee Company
Associations (cont.)
Role
name
Association
name
instructor
StaffMember Student
1..* instructs *
Role
Navigable
Multiplicity (uni-directional)
association * pre -
requisites
Courses
0..3
Reflexive
association
Associations (cont.)
• To clarify its meaning, an association may be named.
• The name is represented as a label placed midway along the association line.
• Usually a verb or a verb phrase.
• A role is an end of an association where it connects to a class.
• May be named to indicate the role played by the class attached to the end of
the association path.
• Usually a noun or noun phrase
• Mandatory for reflexive associations
Associations (cont.)
• Multiplicity
• the number of objects that participate in the association.
• Indicates whether or not an association is mandatory.
Multiplicity Indicators
Exactly one instance 1
Zero or more (unlimited) – no limit * (0..*)
One or more – at least one instance 1..*
Zero or one (optional association) 0..1
Specified range 2..4
Multiple, disjoint ranges 2, 4..6, 8
Aggregation
• A special form of association that models a whole-part relationship between
an aggregate (the whole) and its parts.
• Instances of one class belong to a collection.
• Has a diamond end pointing to the part containing the whole.
• Models a “is a part-part of” relationship.
2..* 1..*
Car Door House
Whole Part
Aggregation (cont.)
• Aggregation tests:
• Is the phrase “part of” used to describe the relationship?
• A door is “part of” a car
• Are some operations on the whole automatically applied to its parts?
• Move the car, move the door.
• Are some attribute values propagated from the whole to all or some of its parts?
• The car is blue, therefore the door is blue.
• Is there an intrinsic asymmetry to the relationship where one class is subordinate to the
other?
• A door is part of a car. A car is not part of a door.
Composition
• A strong form of aggregation
• The whole is the sole owner of its part.
• The part object may belong to only one whole
• Multiplicity on the whole side must be zero or one.
• The life time of the part is dependent upon the whole.
• The composite must manage the creation and destruction of its parts.
1 Circle
Circle Point
3..* Point
Polygon
Generalization
• Indicates that objects of the specialized class (subclass) are
substitutable for objects of the generalized class (super-class).
• One class is the superclass of the other
• “is kind of” relationship.
{abstract} is a An abstract Shape Super
tagged value that class {abstract} Class
indicates that the
class is abstract. Generalization
The name of an relationship
abstract class should Circle Sub Class
be italicized
Generalization
• A sub-class inherits from its super-class
• Attributes
• Operations
• Relationships
• A sub-class may
• Add attributes and operations
• Add relationships
• Refine (override) inherited operations
• A generalization relationship may not be used to model interface
implementation.
The Process of Drawing Class Diagrams
To be able to draw a class diagram, one should follow the steps
below:
• Identify the system that is to be modelled. Eg, library system
• Identify all the objects in the system
• Add attributes to the objects identified
• Add the object methods, multiplicity and relationships between the
objects
• NB: If you struggle too hard to come up with useful attributes or
methods for an object, then perhaps the object chosen is not a
useful one
Class Diagram Example