0% found this document useful (0 votes)
79 views

UML Class Descriptions

The document discusses UML class diagrams including basic and advanced concepts. It covers symbology, classes, attributes, methods, relationships, associations, aggregations, compositions, generalizations, dependencies, and realizations.

Uploaded by

caknill1698
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

UML Class Descriptions

The document discusses UML class diagrams including basic and advanced concepts. It covers symbology, classes, attributes, methods, relationships, associations, aggregations, compositions, generalizations, dependencies, and realizations.

Uploaded by

caknill1698
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

UML Class Diagrams

CSE230 Dae-Kyoo Kim

Agenda

Class Diagrams

Symbology Basic Modeling Intermediate Modeling

Class Diagrams

A class diagram shows:

Classes

Attributes Methods

Interfaces Collaborations Relationships: Dependency, Generalization, Association

A class diagram is a STATIC view of system

Basic Class Diagrams

Class Name

Window
size: Size visibility: boolean display() hide()

Attributes Operations

Basic Class Diagrams


+ # / $ public protected private derived static

Abstract <<abstract>>
<<constructor>> <<query>> <<update>>

Class Scope Variable

Visibility Attribute Name [Multiplicity]:Type = Initial Value Visibility Method Name (Parameter List) : Return-List

Attribute Example (Java implementation)


Note + author: String = unknown + text : String - total : long = 0

public class Note { public String author = unknown; public String text; private static long total = 0; ... }

Operation Example (Java implementation)


Figure
- size: Size - pos : Position + move(pos : Position) + getFigureCount() : long

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; } ... }

Basic Class Diagrams


Class A Superclass Class with parts Class with parts Interface

name Class B Subclass Assembly Class Assembly Class Concrete Class

Association (relationship)

Inheritance (Generalization) (is-a, kind-of)

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

Association (Java implementation)


public class Borrower { Book bk[]; int numBooks; public Borrower() { numBooks = 0; bk = new Book[3]; } // methods that update bk public void borrowBook( Book b ) { bk[numBooks] = b; numBooks++; b.setBorrower( this ); } } public class Book { Borrower currBorr; public void setBorrower( Borrower bw ) { currBorr = bw; } }

Aggregation

A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts.

Models a is a part-part of relationship.


Car 4 wheels

Wheel Part

Whole

Aggregation (Java implementation)


public class Car { private Wheel wheels[]; ... // wheel objects are created externally and // passed to the constructor public Car( Wheel w1, Wheel w2, ) { // we can check w1, w2, etc. for null // to make sure wheels exist wheels = new Wheel[4]; wheels[0] = w1; wheels[1] = w2; } }

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 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..*

Composition (Java implementations)


public class Car { private Wheel wheels[]; ... public Car() { wheels = new Wheel[4]; // Wheels are created in Car wheels[0] = new Wheel(); wheels[1] = new Wheel(); } ... }

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

A sub-class inherits from its super-class


Attributes Operations Relationships Add attributes and operations Add relationships Refine (override) inherited operations

A sub-class may

Generalization (Java implementation)

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()

Dependency (Java implementation)


public class Bank { public void processTransactions() { // Parser p is a local variable Parser p = new Parser(); p.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

Realization (Java implementation)

public interface List { boolean add(Object o); ... } public class LinkedList implements List { public boolean add(Object o)
{ ... } ... }

Basic Class Diagram (Example)


Head Person

Arm

Student takes

Class

Basic Class Diagram (Example)


Person
+ name : String - ssn : String # birthday : Date / age : int +getName : String -calculateAge : int

Class Diagrams (Advanced)


Cardinality (Multiplicity) 1 0..1 0..n 1..n * Student takes
0..n

Class

Class Diagrams (Advanced)


Important Stereotypes: <<interface>> specify collection of operations to specify services <<type>> specify structure and behavior (not implementation) <<enumeration>> specify discrete values <<implementationClass>> helper class created in detail design <<interface>> ImageReader <<type>> Complex Fundamental Attributes Fundamental behavior <<enumeration>> Status Idle Working Error

readImage writeImage

Class Diagrams (Advanced)


Simple Aggregation (object lifetime) Composite Aggregation (unique member) Can have self-relations:
manager

Exception handling: <<sends>>

manages

employee

Class Diagrams (Advanced)


Patron Book

Checks Out Association Class

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 *

Class Diagrams (Advanced)


Role name instructor 1..* Association name instructs Navigable (uni-directional) association *

StaffMember

Student
Role * pre requisites 0..3

Multiplicity

Courses
Reflexive association

You might also like