You are on page 1of 11

Module 7:

Class Diagrams

1 CS6359.OT1: Module 7 Lawrence Chung


Overview

 Usage of Class Diagrams


 Modeling simple collaborations.
 Modeling logical database schema.
 Forward and reverse engineering.

2 CS6359.OT1: Module 7 Lawrence Chung


Class Diagram
 Class diagrams commonly contain the following:
(explained in the previous modules)
 Classes
 Interfaces
 Collaborations
 Relationships
• Dependencies
• Generalizations
• Associations
 Notes

 Class diagrams are used to model the static design view


of a system, typically in one of the three following ways:

 Vocabulary of the system (See Module 3)


 Collaborations (See Module 2 for definition)
 Logical database schema (not physical database)

3 CS6359.OT1: Module 7 Lawrence Chung


Modeling Simple Collaborations
 Identify the mechanism to be modeled; a mechanism represents some function or behavior.
 For each mechanism, identify the classes, interfaces, and other collaborations that participate in
this collaboration.
 Identify the relationships among those entities.
 Use scenarios to walk through the model.
 The classes in the following diagram collaborate (cooperate) with one another.
* CollisionSensor
PathAgent

Responsibilities
-- seek path Driver
-- avoid obstacles

SteeringMotor MainMotor

Motor
move(d:Direction, s:Speed)
stop()
resetCounter()
Status status()
Integer distance()
4 CS6359.OT1: Module 7 Lawrence Chung
Modeling a Logical Database
 A Logical Database is by and large for detailed design or
implementation. Class diagrams are used to provide more semantics to
the data in the database at the analysis and design phase.
Recall that UML is for conceptual modeling.
 From a general class diagram, first identify classes whose state must be
persistent (e.g. after you turn off the computer, the data survives,
although the program doesn’t).
 Create a class diagram using standard tagged value, (e.g. {persistent} ).
 Expand to include structural details, specifically attributes and
associations.
 Identify common patterns which cause database problems; create
intermediate abstractions if necessary.
 Use tools, if available, to transform logical design (e.g., tables and
attributes) into physical design (e.g., layout of data on disk and indexing
mechanisms for fast access to the data).

5 CS6359.OT1: Module 7 Lawrence Chung


Example Logical Database
School Department
0..1
{ persistent} { persistent}
name : Name
name : Name
address : String
phone : Number addInstructor()
1..* removeInstructor()
addStudent()
removeStudent() getInstructor()
1..*
getStudent() getAllInstructors()
getAllStudents()
addDepartment() 1..*
removeDepartment()
getDepartment()
getAllDepartments()

1..*

* 1..* 1..* 0..1 chairperson

Student Course Instructor


{ persistent} { persistent} { persistent}

name : Name * * name : Name * 1..* name : Name


studentId : Number courseId : Number

6 CS6359.OT1: Module 7 Lawrence Chung


Forward Engineering
 How do we translate a collaboration into a logical database schema
+ database operations?
 Forward Engineering involves the process of transforming a model
into code through a mapping to an implementation language.
 Steps
 Identify the rules of mapping to a specific language.
 Selectively use UML to match language semantics (e.g. mapping multiple inheritance in a
collaboration diagram into a programming language with only single inheritance mechanism).
 Use tagged values to identify language.
 Use tools when possible.
successor public abstract class EventHandler
EventHandler
{
{ Java} private EventHandler
Client currentEventId : Integer successor;
source : Strings
{ Java} private Integer
handleRequest() : void currentEventId;
private String source;

GuiEventHandler EventHandler() {}
{ Java}
7 CS6359.OT1: Module 7public void handleRequest() {}
Lawrence Chung
}
Reverse Engineering
 How do we translate a logical database schema + database operations
into a collaboration?
 Reverse Engineering involves the process of transforming code into a
model through mapping from a specific implementation language.
 Steps
 Identify the rules of mapping from a specific language.
 Use a tool; point the tool to the code.
 Query the model to obtain desired information for the model.

successor public abstract class EventHandler


EventHandler
{
{ Java} private EventHandler
Client currentEventId : Integer successor;
source : Strings
{ Java} private Integer
handleRequest() : void currentEventId;
private String source;

GuiEventHandler EventHandler() {}
{ Java}
8 CS6359.OT1: Module 7public void handleRequest() {}
Lawrence Chung
}
Hints & Tips
 Separate your analysis models from your design models.
 They are at different levels of abstraction.
 They have different contextual vocabulary.
 Elements of a well-structured class diagram.
 Focuses on one aspect of a system’s static design view. (e.g., from
performance aspect of the static structure of the system)
 Contains only essential elements for that aspect.
 Provides sufficient details for the level of abstraction.
 Give diagrams a name that communicates their purpose.
 Diagram layout.
 Minimize crossing of arcs.
 Co-locate semantically related elements.
 Use notes and color as visual cues.
 In general one relationship type will dominate each diagram;
don’t confuse the issue.

9 CS6359.OT1: Module 7 Lawrence Chung


Summary
 Class diagram contents.
Classes, Interfaces ,Collaborations, Relationships, Notes

 Usage of Class Diagrams


 Modeling simple collaborations.
 Modeling logical database schema.
 Forward and reverse engineering.

Simple Collaboration Logical Database

10 CS6359.OT1: Module 7 Lawrence Chung


Points to Ponder
 What are the differences between a property and an
attribute?
 Give an example of a low performance design vs. a high
performance design.
 How would you map multiple inheritance into single
inheritance using Java?
 How would you map a class hierarchy into a logical
database? Show a couple of different ways and discuss the
tradeoffs between the two.
 Give an example illustrating possible differences between a
use case and a scenario.
 Given an implementation, what would be the size of the
target space during the reverse engineering?
 If the mapping between an implementation and its
corresponding design through reverse engineering is not 1-1,
how would you come up with a good design?

11 CS6359.OT1: Module 7 Lawrence Chung

You might also like