Reading: chapter 16, Applying UML and Patterns (3/e), Craig Larman
260CT_lect10 @Dr Hong Guo & Coventry University 1 260CT_lect10 @Dr Hong Guo & Coventry University 2
Also referred to in UML simply as a class diagram • Some concepts will not be present in the design
– Actors, may be included in later cycles
The Notation is basically the same as for the
Domain (Conceptual) Model. Design Class Diagrams are usually created in parallel with
interaction diagrams (e.g. Sequence Diagrams,
Collaboration Diagrams)
260CT_lect10 @Dr Hong Guo & Coventry University 3 260CT_lect10 @Dr Hong Guo & Coventry University 4
ClassName
attribute
Analyze use cases (fully dressed) and/or interaction diagrams for attribute: type
classes ATTRIBUTE : type = initial value
• Draw them in a class diagram /derivedAttribute
Duplicate the attributes from the associated concepts in the domain - privateAttribute
model. + publicAttribute
# protectedAttribute
• Attributes are usually assumed private if no visibility is given class attribute
Add method names by cross-referencing to interaction diagrams method1()
Add type information to attributes & methods method2(parameter list ) : return type
abstractMethod()
Add directional associations between classes to support attribute + publicMethod()
visibility - privateMethod()
Add dependency relationship lines # protectedMethod()
class method()
260CT_lect10 @Dr Hong Guo & Coventry University 5 260CT_lect10 @Dr Hong Guo & Coventry University 6
1
The methods of each class are identified from the use cases or If using a CASE tool with code generation
from the collaboration diagrams
• All type details are required but not necessarily
• Can be automatically generated by CASE tool shown
Some methods can be omitted
• Create methods, e.g. constructor methods in Java or C++
• Attribute accessor & mutator functions For Software Developers
Methods on multiobjects (i.e. a collection class) • Exhaustive detail may affect noise-to-value ratio
• Interpret as a message to the container
• Containers add noise with little new information … so
usually excluded
260CT_lect10 @Dr Hong Guo & Coventry University 7 260CT_lect10 @Dr Hong Guo & Coventry University 8
Room Student
• A dependency relationship indicates
- number : String - id : int
that one element has knowledge of - myProject : Project
another element. + getNumber() : String public class Student {
private int id; …
• In class diagrams this means 1 venue + setProject(Project p)
private Project myProject;
− Parameter visibility + notePresentation(Presentation p)
public void setProject(Project p) {
− Global visibility Presentation myProject = p;
− Locally declared visibility - time : DateTime }
Example: the Student has parameter - venue : Room public void notePresentation( Presentation p) {
visibility to Presentation, the method … Room r = p.getRoom() ; //r is a local variable
noteP… invokes getNumber on a Room System.out.println(“Room: ” + r.getNumber() );
1 speaker
System.out.println(“Time: ” + p.getTime() );
Student
Project }
- id : int 1 … Objects communicate
… - code : String }
via sending messages…
+ notePresentation(Presentation) myProject …
260CT_lect10 @Dr Hong Guo & Coventry University 11 260CT_lect10 @Dr Hong Guo & Coventry University 12