Title: Structural Modeling: Class Diagrams
1Structural Modeling Class Diagrams
2Class Diagrams
- Provide static view of system
- Most common type of diagram in OOAD
- Forms basis for component and deployment diagrams
- Shows
- Classes
- Interfaces
- Collaboration
- And their relationships
3Classes
- Definition of the word class
- Oxford a number of individuals having a
character or feature in common - Webster a number of persons or things regarded
as forming a group by reason of common
attributes, characteristics, qualities or traits
4Classes in everyday life
- Based on similar values for a particular, or
group of attributes - All purple dinosaurs all green apples all
Jesuits - Based on the range of an attribute
- Everyone who is between 18-21 years of age
- Based on similar behavior
- Everyone who sleeps in class everyone in the
ECIS program
5All about Classes
- Based on the notion of abstraction
- Starts with identification of all common
characteristics of a set of elements - All objects belong to a class
- Objects represent an instance of a class
- Software objects are built from a class through
instantiation
6Representation of a Class
CLASS NAME
Attributes
Operations ( )
7Representation of a Class
MOTORCYCLE
Color Maximum Speed Engine
Start ( ) Brake ( )
8Purpose of Class Diagrams
- To model the vocabulary of the system
- What lies within and without the system
- To model simple collaborations
- To visualize the relationship between classes
- To model a logical database schema
- Three major types of constructs in class diagrams
- Inheritance structure
- Association structure
- Aggregation structure
9Additional Concepts
- Aggregation
- A relationship between two classes where the
instances of one class are, in some way,
components, members , or contents of the
instances of the other class (from Brown, 2002) - Types
- Component (assembly)
- Container (contents)
- Collection (Member)
10Aggregation Component
Car
Body
Transmission
Engine
Consists of
Car Part
11Class Hierarchies
Vehicle
Land
Air
Bike
Car
Helicopter
Plane
(referred to as Generalization)
12Problems with Classification
Animal
Two-legged
Four-legged
Carnivore
Herbivore
Carnivore
Herbivore
Why should I classify this way instead of
13Class Hierarchies
Animal
Herbivore
Carnivore
4 legs
2 legs
4 legs
2 legs
This way?
14Multiple Generalization
Animal
Herbivore
Carnivore
Two Legged
Four legged
Dog
15Subclass Partitioning
- Disjoint vs. Overlapping
- Based on mutually exclusive subgroups
- Incomplete vs. Complete
- Coverage of the entire set
Powered Vehicle
ANIMAL
Disjoint and incomplete
Overlapping and complete
Plane Car Truck
Herbivore Carnivore
16Relationships Between Classes
- Associations
- Objects are linked
- Classes are associated
- Represented as
(a link)
SU University
David Student
University
Student
(an association)
17Multiplicity
- Sometimes called the cardinalityof a
relationship - The number of instances of each class that are or
can be involved in a given association
1
University
Student
18Other Examples
Driver
Bus
Customer
Product
Student
Course
1
Advisor
Student
19Roles and multiplicity
1
University
Student
0..1
University
Teacher
May be replaced by..
teacher
employer
0..1
University
Person
1
student
20An example
Aggregation (composed of..)
COMPANY
located
OFFICES
DEPARTMENT
Address Stringvoice number
Name Name
constraint
association
roles
subset
generalization
manager
member
1..
1
PERSON
HEADQUARTERS
Name NameempID IntegerTitle String
interface
Getphoto() Getsound() Getcontact() Getpersrec()
PersonnelRecord
taxId string Salary currency
21Generalization vs. Aggregation
- Can sometimes be confusing
- Distinction can be made based on verb used
- Generalization
- The phrase IS A KIND OF
- A car is a kind of vehicle
- Aggregation
- The phrase HAS A/AN
- A car has an engine
22An Example
BURNING LAMP
LAMP
ELECTRIC LAMP
BASE
WIRE
SWITCH
FLOURESCENT
INCANDESCENT
SOCKET
BULB