I. Implementation Model: Mapping Designs to Code (Chapter 20) A. Programming and the Developement Process (20.1) B. Mapping Designs to Code (20.2) 1. Creating class definitions (20.3) 2. Add reference attributes ------------------------------------------ ADDING REFERENCE ATTRIBUTES |------------------------| | Register | |------------------------| | | |------------------------| | endSale() | | enterItem(ItemID, int) | | makePayment(Money) | |------------------------| | 1 | | Captures | | | 1 v |-----------------------| | Sale | |-----------------------| | date : Date | | isComplete: boolean | | time: Time | |-----------------------| | makeLineItem( | | ProductSpecification,| | int) | |-----------------------| Suggests that Register have a Sale field: public class Register { private Sale capturedSale; ... } ------------------------------------------ 3. mapping attributes We have both date and time attributes in Sale, but Java has a built-in class Date that holds both, so what should we use for a field in a Java implementation? 4. creating methods from interaction diagrams (20.4) ------------------------------------------ public class Register { private ProductCatalog catalog; private Sale sale; public enterItem(ItemID id, int qty) { ProductSpecification spec = catalog.getSpecification(id); sale.makeLineItem(spec, qty); } // ... } public class Sale { private ArrayList lineItems = new ArrayList(); public makeLineItem( ProductSpecification spec, int qty) { lineItems.add( new SalesLineItem(spec, qty)); } // ... } ------------------------------------------ 5. Container/Collection Classes in Code ------------------------------------------ import java.util.HashMap; public class ProductCatalog { private HashMap map = new HashMap(); public ProductSpecification getSpecification(ItemId id) { ProductSpecification ret = (ProductSpecification)map.get(id); if (id != null) { return id; } else { // no errors this iteration System.err.println( "got bad product id"); System.exit(1); } } } ------------------------------------------ C. Order of implementation (20.8) What order would you implement the classes for the POS system in? Which ones could happen in parallel? If you implemented from top down, what stubs would you have to write? D. Test-first programming (20.9) E. example listings (see section 20.11)