LARMAN CD MODULES

Module 14

Mapping Design to Code

Introduction

It's all very well to have a lot of fancy designs, but as we all know, designs don't crash. So this module introduces us to mapping our designs to code. The code, after all, is what creates a viable software system.

Designing Class Definitions in Java

What we see in the following java definition is:

- Register has visibility to a Product Catalog via a private attribute
- Register has visibility to a Sale via a private attribute
- Register has a method endSale()

Showing Multiplicity or Collection Attributes

The multiplicity of Sale to SalesLineItems is "one or more". Therefore, the code must show this as a collection of Sales Line Items. The following code shows this being implemented as a List interface type and an instance of an Array List. It could be a map, a list or an array.

Runnable Interfaces

The following diagram shows two UML notations for indicating that we are implementing an Interface. The left side shows the "lollipop" way of indicating an interface, the right hand side shows the alternative way using an arrow. In this case we are implementing the runnable interface with a method "Run".

The mapping to code is shown in the bottom half of the diagram. The implementation method "run()" implements the interface.

Defining Methods

The following diagram depicts our POS system interaction diagram and the translation of the messages to code. Here we are sending a "getSpecification" message to the Product Catalog and getting a Product Specification returned. That specification is then passed to a Sale object as a parameter in the "makeLineItem" message.

The mapping of design to code is straightforward here, but in reality the mapping of diagrams to code is not simple. In general, the diagrams are used to rough out the major ideas in code, but in reality a lot of details required for the code are ignored in the diagram. In other words, think of the diagrams as a first-step approximation of what will be required in the code.

Implementation Order

The following Class Diagram can give us some hints as to the appropriate order of implementing methods. The basic idea is that if a class does not have dependencies on other classes, they can be implemented (and tested) first.

Home

Module 1 | Module 5 | Module 6 | Module 7 | Module 8 | Module 9

Module 10 | Module 12 | Module 13 | Module 14