UML: Class Diagrams Flashcards
Class Diagrams:
Basic Description
Used to show the classes in a system and the associations/relations between the classes.
- When developin models in the early stages of the SE process, classes may represent objects in the real world
- Classes are represented with named boxes, including sections for Class Attributes and Operations
- Relations are represented with lines drawn between two or more classes
Class Diagrams:
Classes
A class is represented by a box with three sections:
- Class Name
- Attributes
- Operations/Methods
The Visibility of Attributes and Operations is indicated with a symbol just before the name:
- Public (+)
- Private (-)
- Protected(#)
Class Diagrams:
Categories (3)
and Types of Relations (5)
Categories
- Runtime Relation
- Consistent Relations
- Whole Part Relations
Types
- Dependency ( Runtime)
- Association (Consistent)
- Composition (Whole Part)
- Aggregation (Whole Part)
- Generalization
Class Diagrams:
Relations:
Associations
Represents a general association between two objects with an arrowed line
- Objects on both sides can “find” each other
- Relation is consistent in time
- May also have an Association Class that is attached to or represents the association
- In this case, a dotted line goes from the association line to the association class (in a T)
- Multiplicity is marked at each end of the relation:
- * - unbounded (1 or more)
- Specific number or range
Class Diagrams:
Relations:
Aggregation
Represents a “Whole Part” or “Has A” relationship between classes
Indicated with a diamond symbol attached to the “Owner” class.
Class Diagrams:
Relations:
Generalization
Represents Inheritence/Subclasses
A white arrow points to the Parent Class, with the line branching out to each of the Child Classes
Class Diagrams:
Relations:
Composition
A stronger form of aggregation.
Contained classes live exclusively within the lifecycle of their Owner/Container.
Represented by a black diamond attached to the Container class, with an arrow pointing to the contained class and an indication of multiplicity.
Usage example: UI components in a Window object
Class Diagrams:
Relations:
Aggregation vs Composition
Aggregation
Composition
“Parts” can be shared by several “wholes”
“Parts” are exclusive to one “whole”
“Parts” may live independently of a “whole”
Parts exist only as a part of the whole, are destroyed when the whole is destroyed
The Whole is not solely responsible for the part
The whole is solely responsible for the part
White diamond with arrow
White diamond, no arrow
Class Diagrams:
Relations:
Dependency
Indicates that one object affects the state of another
The most abstract type of relation.
- Represented with a dotted line with open arrow
- Relation line is labeled with some sort of action:
- << action >>
- Such as << creates >> or << modifies >>