Title: Design Class Diagrams
1Design Class Diagrams
2Overview
- To frame our discussion consider
3Outline
4Creating Design Class Diagrams
- Class diagrams are created once
- interaction diagrams are complete
- conceptual model has been refined
5Classes
- Classes are an important building block for
object-oriented systems. A class is the
description of a set of objects that share the
same attributes, operations. Relationships, and
semantics. - You use classes to capture the vocabulary of the
system you are developing.
6Class Diagrams
- A class diagram show a set of classes,
interfaces, and collaborations and their
relationships. - Class diagrams illustrate the static view of a
system.
7Design Class Diagrams
- A design class diagram illustrates the
specifications for software classes and
interfaces in an application. - Information Content
- classes associations, attributes
- interfaces
- methods
- attributes type information
- navigability
- dependencies
8Important!
- The design class diagram is a model for a
software entity.
9Making a Design Class Diagram
- Analyze the interaction diagrams to determine the
classes participating in a software solution. - Draw them in a class diagram.
- Add the attributes for the classes from the
conceptual model. - Add method names by reviewing the interaction
diagrams. - Add type information for attributes and methods.
- Add associations required to support visibility.
- Add navigability arrows to indicate the direction
of visibility. - Add dependency relationships.
10Example
11Navigability
- Navigability is property of the role which
indicates that it is possible to navigate across
the association from objects to other objects.
Navigability implies visibility.
12Building Systems by Assembling Parts
- Composition
- an organized collection of components interacting
to achieve a coherent, common behavior - Association
- a composition of independently constructed and
externally visible parts. - Key Language Ideas
- Passing objects by reference, pointer
13Communicating Objects by Reference and by Pointer
- Uses
- result parameters to allow the sender to see the
changes made to the object by the execution of
the receiver's method, - associations to establish connections among
objects that allow the objects to interact beyond
the duration of a single method invocation, and - managers to allow an object of one class to
create, distribute, or otherwise manage objects
of another class.
14Composition
- An organized collection of components interacting
to achieve a coherent, common behavior.
15Forms of Composition
- Association
- A composition of independently constructed and
externally visible parts - Aggregation
- A composition that encapsulates (hides) the parts
of the composition.
16Aggregation
- A composition that encapsulates (hides) the parts
of the composition.
17Association
- A composition of independently constructed and
externally visible parts
18Passing Pointers
- // ptrref.cpp Defines the entry point for the
console application. - //
- include "stdafx.h"
- include "iostream.h"
- void swap2 (int i, int j)
- void main()
-
- int a1,b2,c3,d4
- coutltlt"a "ltltaltlt" b "ltltbltltendl
- swap2(a,b)
- coutltlt"a "ltltaltlt" b "ltltbltltendl
-
- void swap2(int i, int j)
- int t
- ti
19Passing by Reference
- // ptrref.cpp Defines the entry point for the
console application. - //
- include "stdafx.h"
- include "iostream.h"
- void swap1 (int i, int j)
- void main()
-
- int a1,b2
- coutltlt"a "ltltaltlt" b "ltltbltltendl
- swap1(a,b)
- coutltlt"a "ltltaltlt" b "ltltbltltendl
-
- void swap1(int i, int j)
- int t
- ti
- ij
20Objects for Communication
- Messages can contain parameters. These
parameters may be simple types - int, float, char
- or other objects.
21Frame - v1
- class Frame
- private
- BasicFrame frame // hidden
implementation - char name // title on
visible frame - int xCoord,yCoord // location
of upper left hand corner - int height, width // shape of
the frame - bool closed
- void CreateIfNeeded()
- public
- Frame(char name, int x, int y, int w, int h)
- Frame(char name, int x, int y)
- Frame(char name)
- Frame()
22Frame - v2
- class Frame
- private char name
- BasicFrame frame
- Location location
- Shape shape
- void CreateIfNeeded()
- public
- Frame(char name, Location loc, Shape sh)
- Frame(char name, Location loc)
- Frame(char name, Shape sh)
- Frame(char name)
- Frame()
- Frame()
23Advantages
- 1. Using Shape and Location capture important
concepts from the application domain. - 2. The concepts can communicate important
information to the reader of the program. - 3. Provides increased flexibility for the
programmer. - 4. Makes certain constructs possible.
24Class Location
- class Location // Version 1
- private
- int currentX, currentY
- public
- Location(int x, int y) // specific
location - Location() // default location
- int Xcoord() // return x-axis
coordinate - int Ycoord() // return y-axis
coordinate
25Class Shape
- class Shape // Version 1
- private
- int currentWidth, currentHeight
- public
- Shape(int width, int height) // specific
shape Shape() // default shape - int Height() // return height
- int Width() // return width
26Constructors
- Frame(char name, Location loc, Shape sh)
- Frame(char name, Location loc)
- Frame(char name, Shape sh)
27Objects by Copy
- Frame smallTop(Small, nearTop, smallSquare)
- nearTop and smallSquare are objects that are
copied during the construction process.
28Advantages of Copy
- Sender is assured that changes made to the object
by the receiver do not change the object from the
senders perspective.
29Limits in Use
- Not appropriate when
- Object must be shared between sender and
receiver. - Sender wants the receiver to modify the object.
- Dealing with very large objects.
30Returning Objects
- Objects can be returned from a method.
- Old
- Void TextSize(char msg, int width, int
height) - New
- Shape TextSize(char msg)
31Example
- Frame display
- char msgHello There
- Location msgLocation(50,50)
- display.DrawText(msg, msgLocation)
- Shape msgShapedisplay.TextSize(msg)
- display.clear(msgLocation, msgShape)
32Frame Class
- class Frame
- private char name
- BasicFrame frame
- Location location
- Shape shape
- void CreateIfNeeded()
- public
- Frame(char name, Location loc, Shape sh)
- Frame(char name, Location loc)
- Frame(char name, Shape sh)
- Frame(char name)
- Frame()
- Frame()
- void MoveTo(Location loc) //
change position - void Resize(Shape sh) //
change shape - void Resize( float factor) //
- void DrawText(char msg, Location loc) //
display msg at (x,y) - Shape TextSize (char msg) //
find size of msg - void DrawLine(Location p1, Location p2) //
draw line from point p1 to point p2
33Problem
- Display a string of characters that appear to
blink.
34Primitive Message Class
- class PrimitiveMessage
- private
- char msgText
- public
- PrimitiveMessage(char text)
- void SetText(char newText)
- char GetText()
- PrimitiveMessage()
35Frame window("Message Test", Location(100,100),
Shape(200,200)) PrimitiveMessage greeting("Hello
World") Location greetingLocation(20,50) int
onoff void OnStart() window.Clear()
window.DrawText(greeting.GetText(),
greetingLocation) onoff1 void
OnTimerEvent() if (onoff 1) Shape
greetingShape window.TextSize(greeting.GetText()
) window.Clear(greetingLocation,
greetingShape) onoff 0 else
window.DrawText(greeting.GetText(),
greetingLocation) onoff 1 void
OnPaint() if (onoff 1)
window.DrawText(greeting.GetText(),
greetingLocation)
36Responsibilities based on Primitive Message Class
Design
37Message
class Message private char
text // text being displayed
Location location // at this
location Frame frame //
in this window public Message(char
textString, Location whereAt)
Message(Location whereAt) void
DisplayIn(Frame whichFrame) void
MoveTo(Location newLocation) void
SetText(char newText) char GetText()
void Draw() void Clear()
Message()
38Frame window("Message Test", Location(100,100),
Shape(200,200)) Message greeting("Hello World!",
Location(20,20)) int onoff void OnStart()
greeting.DisplayIn(window) greeting.Draw()
onoff 1 void OnMouseEvent(char
frameName, int x, int y, int buttonState) void
OnTimerEvent() if (onoff)
greeting.Clear() onoff 0 else
greeting.Draw() onoff 1 void
OnPaint() if (onoff) greeting.Draw()
39Responsibilities based on Message Class Design
40Blinking Message
class BlinkingMessage private char
text // text being displayed
Location location // at this
location Frame frame // in
this window int visible void
Clear() void Draw() public
BlinkingMessage(char textString, Location
whereAt) BlinkingMessage(Location whereAt)
void DisplayIn(Frame whichFrame) void
MoveTo(Location newLocation) void
SetText(char newText) char GetText()
void Blink() void Redraw() BlinkingMessage()
41Frame window("Message Test", Location(100,100),
Shape(200,200)) BlinkingMessage greeting("Hello
World", Location(20,50)) void OnStart()
window.Clear() greeting.DisplayIn(window)
greeting.Blink() void OnTimerEvent()
greeting.Blink() void OnPaint()
greeting.Redraw() void OnMouseEvent(char
frameName, int x, int y, int buttonState)
42Responsibilities based on Blink Message Class
Design