Mapping Designs to Code Chapter 20 Applying UML

  • Slides: 17
Download presentation
Mapping Designs to Code Chapter 20 Applying UML and Patterns -Craig Larman 1

Mapping Designs to Code Chapter 20 Applying UML and Patterns -Craig Larman 1

Mapping Designs to Code l Process: Write source code for • Class and interface

Mapping Designs to Code l Process: Write source code for • Class and interface definitions • Method definitions 2

Design Class Diagrams l l l DCDs contain class or interface names, classes, method

Design Class Diagrams l l l DCDs contain class or interface names, classes, method and simple attributes. These are sufficient for basic class definitions. Elaborate from associations to add reference attributes. 3

Reference Attributes An attribute that refers to another complex objects. l Reference Attributes are

Reference Attributes An attribute that refers to another complex objects. l Reference Attributes are suggested by associations and navigability in a class diagram. l Example: A product specification reference on a Sales Line Item. So here we can use product spec as a complex reference attribute to sales line item class. 4

Role Names l Each end of an association is a role. Reference Attributes are

Role Names l 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). 5

Creating methods from Interaction Diagrams l l Interaction Diagrams are used to specify methods.

Creating methods from Interaction Diagrams l l Interaction Diagrams are used to specify methods. They give most of the details for what the method does. 6

Containers and Collections l l Where an object must maintain visibility to a group

Containers and Collections l l Where an object must maintain visibility to a group of other objects, such as a group of Sales Line Items in a Sale, object-oriented languages often use an intermediate container or collection. These will be suggested by a multiplicity value greater than one on a class diagram. 7

Working Example: PM 8

Working Example: PM 8

PM: Use Case Diagram 9

PM: Use Case Diagram 9

PM: Class Diagram 10

PM: Class Diagram 10

PM: Class to Code l l l l class Work. Package; class Project; class

PM: Class to Code l l l l class Work. Package; class Project; class Activity; class Task; class Work. Product; class Resource; class Skill; class Resource. XSkill; 11

PM: Class to Code class Work. Package { // Details omitted }; class Project

PM: Class to Code class Work. Package { // Details omitted }; class Project : public Work. Package { private: Collection. By. Val<Activity> the. Activity; }; class Activity : public Work. Package { private: Project *the. Project; Collection. By. Val<Task> the. Task; Collection. By. Ref<Work. Product> the. Work. Product; }; 12

PM: DCD Mapping 13

PM: DCD Mapping 13

PM: DCD Code class Project Date get. Start. Date (void); { private: void add.

PM: DCD Code class Project Date get. Start. Date (void); { private: void add. Activity (const Activity char *Name; &the. Activity); char *Descr; Collection. By. Ref<Activity> Date Start. Date; get. All. Acitivities (void); static int Number. Of. Projects; static int get. Number. Of. Projects public: (void); Project (char *Name); void save (void); Project (void); ~Project (void); void load (char *Name); char *get. Name (void); protected: void set. Name (char *the. Name); bool has. Activities (void); }; void set. Descr (char *Descr); char *get. Descr (void); int Project: : Number. Of. Projects = 0; void set. Start. Date (Date the. Start. Date); 14

PM: Sequence Diagram 15

PM: Sequence Diagram 15

PM: Sequence to Main void main (void) { char *Name; char *Descr; Date Start.

PM: Sequence to Main void main (void) { char *Name; char *Descr; Date Start. Date; Project a. Project; // provide project Name, descr, and startdate a. Project. set. Name (Name); a. Project. set. Descr (Descr); a. Project. set. Start. Date (Start. Date); a. Project. save (); } 16

Other References l l l http: //www. martinig. ch/mt/index. html http: //www. sparxsystems. com.

Other References l l l http: //www. martinig. ch/mt/index. html http: //www. sparxsystems. com. au/UML_Tutori al. htm http: //archive. devx. com/free/mgznarch/vcdj/1 999/jun 99/uml 1. asp 17