Implementation Model Mapping Designs to Code Ch 20

  • Slides: 8
Download presentation
Implementation Model: Mapping Designs to Code Ch. 20 1

Implementation Model: Mapping Designs to Code Ch. 20 1

Defining a Class with Methods and Simple Attributes public class Sales. Line. Item {

Defining a Class with Methods and Simple Attributes public class Sales. Line. Item { private int quantity; } public Sales. Line. Item(Product. Specification spec, int, qty) {. . . } public Money get. Subtotal() {…} … Sales. Line. Item quantity : Integer get. Subtotal(): Money * Described-by Product. Specification description : Text 1 price : Money item. ID : Item. ID 2

Adding Reference Attributes public class Sales. Line. Item { } private int quantity; private

Adding Reference Attributes public class Sales. Line. Item { } private int quantity; private Product. Specification product. Spec; // reference attribute … Sales. Line. Item quantity : Integer get. Subtotal(): Money * Described-by Product. Specification description : Text 1 price : Money item. ID : Item. ID 3

Reference Attributes and Role Names public class Sales. Line. Item { } private int

Reference Attributes and Role Names public class Sales. Line. Item { } private int quantity; private Product. Specification product. Spec; … Sales. Line. Item quantity : Integer get. Subtotal(): Money * Product. Specification description : Text Described-by 1 price : Money product. Spec item. ID : Item. ID 4

Creating Methods from Interaction Diagrams add. Line. Item(item. ID, quantity) : Register 2 :

Creating Methods from Interaction Diagrams add. Line. Item(item. ID, quantity) : Register 2 : make. Line. Item(spec, quantity) 1: spec : = get. Specification(item. ID) : Sale : Product. Catalog 1. 1: spec : = find(item. ID) : Product. Specification 2. 2 : add(sli) : Sales. Line. Item 2. 1 : create(spec, quantity) sli: Sales. Line. Item 5

The Register – add. Line. Item method • The add. Line. Item collaboration diagram

The Register – add. Line. Item method • The add. Line. Item collaboration diagram will be used to illustrate the Java definition of the add. Line. Item method. • In which class does add. Line. Item belong to? • The add. Line. Item message is sent to a Register instance, therefore the add. Line. Item method is defined in class Register. public void add. Line. Item(item. ID, int quantity); • Message 1. A get. Specification message is sent to the product. Catalog to retrieve a product. Specification spec = catalog. get. Specification(item. ID); • Message 2: The make. Line. Item message is sent to the Sale. sale. make. Line. Item(spec, quantity); 6

A Skeletal definition of Register Class public class Register { private product. Catalog catalog;

A Skeletal definition of Register Class public class Register { private product. Catalog catalog; private Sale sale; Product. Catalog public Register (Product. Catalog pc) {…} public void end. Sale(); public void add. Line. Item (Item. ID item. ID, int quantity); public void make. New. Sale() {…} public void make. Payment (Money cash. Tendered) {…} get. Specification() 1 Looks-in } Register 1 Captures end. Sale() add. Line. Item() make. New. Sale() make. Payment() 1 1 Sale Date : Date is. Complete : Boolean time : Time become. Complete() make. Line. Item() make. Payment() get. Total() 7

Container/Collection Classes in Code Sale Date : Date is. Complete : Boolean time :

Container/Collection Classes in Code Sale Date : Date is. Complete : Boolean time : Time become. Complete() make. Line. Item() make. Payment() get. Total() public class Sale {. . . } private Vector line. Items; Sales. Line. Item Contains 1 1. . * quantity : Integer get. Subtotal(): Money A container class is necessary to maintain attribute visibility to all the Sales. Line. Item instances. Vector is an example of a dynamic data structure. 8