Skip to content

Lesson 5 Practice — Shopping Cart Collaboration ​

Create:

text
ZCL_CART_ITEM_###
ZCL_SHOPPING_CART_###
ZCL_ABAP_L05_PRACTICE_###

Cart Item ​

Private state:

text
product_code
name
unit_price
quantity

Methods:

text
constructor
increase_quantity
get_quantity
get_line_total
get_product_code

Rules:

text
price >= 0
quantity >= 1

Shopping Cart ​

Store a table of references to ZCL_CART_ITEM_###.

Methods:

text
add_item
get_item_count
get_total

get_total must ask each item for get_line_total.

Questions ​

  1. Why is line total derived rather than stored?
  2. Why does Cart store references?
  3. Which class owns quantity validation?
  4. What is a private helper method useful for?
  5. Why is a generic public setter for every field often a weak API?