of 17
8/12/2019 Larman Chapter 20.ppt
1/17
1
Mapping Designs to Code
Chapter 20
Applying UML and Patterns
-Craig Larman
8/12/2019 Larman Chapter 20.ppt
2/17
2
Mapping Designs to Code Process: Write source code for
Class and interface definitions
Method definitions
8/12/2019 Larman Chapter 20.ppt
3/17
3
Design Class Diagrams DCDs contain class or interface names,
classes, method and simple attributes.
These are sufficient for basic classdefinitions.
Elaborate from associations to add
reference attributes.
8/12/2019 Larman Chapter 20.ppt
4/17
4
Reference Attributes
An attribute that refers toanother complex objects.
Reference Attributes aresuggested by associations and
navigability in a class diagram.
Example: A productspecification reference on aSales Line Item. So here wecan use product spec as acomplex reference attribute to
sales line item class.
8/12/2019 Larman Chapter 20.ppt
5/17
5
Role Names
Each end of an
association is a role.
Reference Attributes
are often suggested by
role names.(use role names as the
names of reference
attributes).
8/12/2019 Larman Chapter 20.ppt
6/17
6
Creating methods from
Interaction Diagrams
Interaction Diagrams
are used to specify
methods.
They give most of thedetails for what the
method does.
8/12/2019 Larman Chapter 20.ppt
7/17
7
Containers and Collections
Where an object mustmaintain visibility to agroup of other objects,such as a group of Sales
Line Items in a Sale,object-orientedlanguages often use anintermediate container orcollection.
These will be suggested
by a multiplicity valuegreater than one on aclass diagram.
8/12/2019 Larman Chapter 20.ppt
8/17
8
Working Example: PM
8/12/2019 Larman Chapter 20.ppt
9/17
9
PM: Use Case Diagram
8/12/2019 Larman Chapter 20.ppt
10/17
10
PM: Class Diagram
8/12/2019 Larman Chapter 20.ppt
11/17
11
PM: Class to Code
class WorkPackage;
class Project;
class Activity;
class Task;
class WorkProduct;
class Resource;
class Skill;
class ResourceXSkill;
8/12/2019 Larman Chapter 20.ppt
12/17
12
PM: Class to Code
class WorkPackage
{ // Details omitted };
class Project : public WorkPackage
{ private: CollectionByVal theActivity; };
class Activity : public WorkPackage
{ private: Project *theProject;
CollectionByVal theTask;CollectionByRef
theWorkProduct; };
8/12/2019 Larman Chapter 20.ppt
13/17
13
PM: DCD Mapping
8/12/2019 Larman Chapter 20.ppt
14/17
14
PM: DCD Code
class Project
{ private:
char *Name;
char *Descr;
Date StartDate;static int NumberOfProjects;
public:
Project (char *Name);
Project (void); ~Project (void);
char *getName (void);
void setName (char *theName);void setDescr (char *Descr);
char *getDescr (void);
void setStartDate (Date
theStartDate);
Date getStartDate (void);
void addActivity (const Activity&theActivity);
CollectionByRef
getAllAcitivities (void);static int getNumberOfProjects(void);
void save (void);
void load (char *Name);
protected:
bool hasActivities (void); };
int Project::NumberOfProjects = 0;
8/12/2019 Larman Chapter 20.ppt
15/17
15
PM: Sequence Diagram
8/12/2019 Larman Chapter 20.ppt
16/17
16
PM: Sequence to Main
void main (void)
{ char *Name; char *Descr;
Date StartDate; Project aProject;// provide project Name, descr, and startdate
aProject.setName (Name);
aProject.setDescr (Descr);
aProject.setStartDate (StartDate);
aProject.save (); }
8/12/2019 Larman Chapter 20.ppt
17/17
17
Other References
http://www.martinig.ch/mt/index.html
http://www.sparxsystems.com.au/UML_Tutorial.htm
http://archive.devx.com/free/mgznarch/vcdj/1
999/jun99/uml1.asp