UML in OOP II: Class Diagrams & Java Code Mapping, Study notes of Computer Science

An overview of uml (unified modeling language), a modeling language used for specifying, visualizing, constructing, and documenting object-oriented software. Uml helps in creating a software 'blueprint' with a simple yet clear abstraction for software design. The history of uml, uml diagrams, and the relationship between uml class diagrams and java code. It includes examples of class diagrams and their mapping to java code.

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-6iy
koofers-user-6iy 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CMSC 132:
Object-Oriented Programming II
Unified Modeling Language
(UML)
Department of Computer Science
University of Maryland, College Park
UML (Unified Modeling Language)
UML is a modeling language for
Specifying
Visualizing
Constructing
Documenting
object-oriented software
Motivation
Software growing larger & complex
Difficult to describe and analyze
Use UML to help
Visualize design of software
Provide abstract model of software
Goals
Provide a software “blueprint”
Simple yet clear abstraction for software
Describe software design
Clearly
Concisely
Correctly
History of UML
Started in 1994
Combines 3 leading OO methods
OMT (James Rumbaugh)
OOSE (Ivar Jacobson)
Booch (Grady Booch)
UML Diagrams
UML provides a number of diagrams that
Describe a model of all or part of system
From a particular point of view
With varying level of abstraction
Using certain set of notations
System
Model 1
Model 2
View 1
View 3
View 2
pf3
pf4
pf5

Partial preview of the text

Download UML in OOP II: Class Diagrams & Java Code Mapping and more Study notes Computer Science in PDF only on Docsity!

CMSC 132:

Object-Oriented Programming II

Unified Modeling Language

(UML)

Department of Computer Science

University of Maryland, College Park

UML (Unified Modeling Language)

UML is a modeling language for

Specifying Visualizing Constructing Documenting

object-oriented software

Motivation

Software growing larger & complex

Difficult to describe and analyze

Use UML to help

Visualize design of software Provide abstract model of software

Goals

Provide a software “blueprint”

Simple yet clear abstraction for software

Describe software design

Clearly Concisely Correctly

History of UML

Started in 1994

Combines 3 leading OO methods

OMT (James Rumbaugh) OOSE (Ivar Jacobson) Booch (Grady Booch)

UML Diagrams

UML provides a number of diagrams that

Describe a model of all or part of system From a particular point of view With varying level of abstraction Using certain set of notations

System Model 1

Model 2

View 1 View 3

View 2

Class Diagram

Represents (static) structure of system

A class diagram displays

Information for class Relationships between classes

Class Diagram

Batteryload()

1 2 PushButtonstate Timenow() push()release()

1 1

1 1

1 2 blinkIdxblinkSeconds() blinkMinutes()blinkHours() stopBlinking()referesh()

LCDDisplay

SimpleWatch

Class

Multiplicity Association

Attributes Operations

Class diagrams represent structure of system

Class Diagrams

Information for class contains

Name State Behavior

Class Diagram

Class name is required

Other information optional

State, behavior Types, visibility…

UML Class Diagrams ↔ Java Code

Different representation of same information

Name, state, behavior of class Relationships between classes

Should be able to derive one from the other

Motivation

UML ⇒ Java Implement code based on design written in UML Java ⇒ UML Create UML to document design of existing code

Java → UML : Clock Example

Java

class Clock { // name // state int seconds; int minutes; int hours; // behavior void start(); void adjustTime(); void reset(); }

Java Code Class Diagram

Association w/ Navigation

Navigation information

Relationship between classes may be directional Only class A can send messages to class B Arrowhead indicates direction of relationship

Example

class Course { class Lecturer { Lecturer TheBoss; … } }

Association w/o Navigation

Undirected edge

Relationship between classes may be bi-directional Direction of relationship may be unknown

Examples

class Course { class Lecturer { Lecturer TheBoss; Course [ ] class; } }

class Foo class Bar

Permanent Association

Permanent / structural association

Class A contains reference to class B in data field Can view as “has a” relationship Also referred to as composition

Example

class A { class B { B x; … } }

A has a B

Temporary Association (Dependency)

A transitory relationship between classes

Always directed (class A depends on B) Indicates change in class B may affect class A Can view as “uses a” relationship Represented by dotted line with arrowhead

Example

A depends on B

A B

Dependency

Dependence may be caused by

Local variable Parameter Return value

Example

class A { class B { B foo(B x) { … B y = new( ); … … … } } }

UML Examples

Read UML class diagram

Try to understand relationships Practice converting to / from Java code

Examples

Computer disk organization Banking system Home heating system Printing system

UML Example – Computer System

Try to read & understand UML diagram

  • CPU is associated with Controllers
  • DiskDrive is associated with SCSIController
  • SCSIController is a (type of) Controller

UML Example – Banking System

  • Bank associated with Accounts
  • Checking, Savings, MoneyMarket are type of Accounts

UML Example – Home Heating System

  • Thermostat associated with (has a) Room
  • Thermostat associated with (has a) Heater
  • ElectricHeater is a specialized Heater
  • AubeTH101D is a specialized Thermostat

UML Example – Library System

Try to read & understand UML diagram

  • Books are associated with (has some) Pages
  • Patron & Shelf depend on (temporarily use) Books

UML → Java : Computer System

UML

Java

class Controller { } class SCSIController extends Controller { }

UML → Java : Computer System

UML

Java

Design code using all available information in UML…

Amateras UML Editor – Eclipse Plugin Violet UML Editor

Drag-n-drop classes

into UML diagram

Auto creates class w/ attributes & methods

Add links manually

No undirected associations Use directed association in both directions instead

Violet UML Editor – Eclipse Plugin UML Summary

UML → modeling language

Visually represents design of software system

We focused on class diagrams

Contents of a class Relationship between classes

You should be able to

Draw UML class diagram given Java code Write Java code given UML class diagram