UML Class Descriptions
UML Class Descriptions
Agenda
Class Diagrams
Class Diagrams
Classes
Attributes Methods
Class Name
Window
size: Size visibility: boolean display() hide()
Attributes Operations
Abstract <<abstract>>
<<constructor>> <<query>> <<update>>
Visibility Attribute Name [Multiplicity]:Type = Initial Value Visibility Method Name (Parameter List) : Return-List
public class Note { public String author = unknown; public String text; private static long total = 0; ... }
public class Figure { private Size size; private Position pos; private static long figureCount = 0; public void move(Position pos) { ... } public static long getFigureCount() { return figureCount; } ... }
Association (relationship)
Aggregation (Part-Of)
Dependency
Realization
Associations
A semantic relationship between two or more classes that specifies connections among their instances A structural relationship specifying that objects of one class are connected to objects of a second (possibly the same) class Example: An Employee works for a Company
Associations (cont.)
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
Borrower 1 currBorr 3 bk[]
Book
Aggregation
A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts.
Wheel Part
Whole
Composition
Multiplicity on the whole side must be one The life time of the part is dependent upon the whole
The composite must manage the creation and destruction of its parts
Line Polygon
2
Point
3..*
Generalization
Indicates that objects of the specialized class (subclass) are substitutable for objects of the generalized class (super-class)
is kind of relationship
An abstract class Generalization relationship Circle Shape Super Class
Sub Class
Generalization
Attributes Operations Relationships Add attributes and operations Add relationships Refine (override) inherited operations
A sub-class may
public abstract class Shape { public abstract void draw(); ... } public class Circle extends Shape { public void draw() { ... } ... }
Dependency
A dependency indicates a semantic relation between two or more classes in which a change in one may force changes in the other although there is no explicit association between them A stereotype may be used to denote the type of the dependency
Bank processTransactions ()
uses
Parser getTransaction()
Realization
A realization relationship indicates that one class implements a behavior specified by another class (an interface or protocol). An interface can be realized by many classes. A class may realize many interfaces.
LinkedList
<<interface>>
List
LinkedList
List
public interface List { boolean add(Object o); ... } public class LinkedList implements List { public boolean add(Object o)
{ ... } ... }
Arm
Student takes
Class
Class
readImage writeImage
manages
employee
TVRS Example
TrafficReport id : long description : String occuredAt : Date reports of 1..* Policeman id : long name : String rank : int <<abstract>> Violation id : long description : String 1..* 1 Offender name : String id : long
TrafficPoliceman 1 issues *
StaffMember
Student
Role * pre requisites 0..3
Multiplicity
Courses
Reflexive association