Choose who creates a cart line

An online shop uses four classes with the following roles:

  • Cart owns the collection of CartLine objects and receives the product identifier, quantity and unit price when an item is added.
  • CartLine stores those three values for one item.
  • ProductCatalog supplies product information but does not retain carts or their lines.
  • CheckoutController receives interface events and forwards requests to Cart.

CartLine construction requires only the three values listed above, and no separate construction service is required. To place construction with the class that both contains the resulting object and has its initialization data, assign responsibility for creating a new CartLine to . Enter the exact class name.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Allocating Responsibilities to Classes Questions: