Applying UML and Patterns: Mapping Designs to Code
- Introduction
- 20.1 Programming and Iterative, Evolutionary Development
- 20.2 Mapping Designs to Code
- 20.3 Creating Class Definitions from DCDs
- 20.4 Creating Methods from Interaction Diagrams
- 20.5 Collection Classes in Code
- 20.6 Exceptions and Error Handling
- 20.7 Defining the Sale.makeLineItem Method
- 20.8 Order of Implementation
- 20.9 Test-Driven or Test-First Development
- 20.10 Summary of Mapping Designs to Code
- 20.11 Introduction to the NextGen POS Program Solution
- 20.12 Introduction to the Monopoly Program Solution
Beware of bugs in the above code; I have only proved it correct, not tried it.
—Donald Knuth
Objectives
- Map design artifacts to code in an object-oriented language.
Introduction
With the completion of interaction diagrams and DCDs for the current iteration of the case studies, there’s more than enough thought and detail to cut some code for the domain layer of objects.
The UML artifacts created during the design work—the interaction diagrams and DCDs—will be used as input to the code generation process.
In UP terms, there exists an Implementation Model. This is all the implementation artifacts, such as the source code, database definitions, JSP/XML/HTML pages, and so forth. Thus, the code being created in this chapter can be considered part of the UP Implementation Model.
Language Samples
Java is used for the examples because of its widespread use and familiarity. However, this is not meant to imply a special endorsement of Java; C#, Visual Basic, C++, Smalltalk, Python, and many more languages are amenable to the object design principles and mapping to code presented in this case study.