A set models a collection whose members are distinct. In a cart, replacing lists with sets expresses the requirement that items should be unique, but Java set equality considers the entire object. section 9.3.1
A set therefore helps communicate an invariant without necessarily enforcing the domain’s intended identity. Two items with the same product and seller identifiers can remain distinct if another attribute, such as price, differs. section 9.3.1
Cart items
A ValidCart can store active and saved items as Set<Item>. If uniqueness depends on a subset of attributes, such as productId and sellerId, a Map<ProductSeller, Item> represents that identity more directly. section 9.3.1
Table 9.2 a refresher on the requirements
|
3
|
When a
customer adds items to their cart
|
|
3.1
|
If the item
is already in the Active cart, the service shall add their quantities
|
|
3.2
|
If the item is already in the Saved cart, the service shall add their quantities and move
the item to Active
|
|
3.3
|
If the
item is not in either cart, it shall be added to Active
|
|
5.0
|
The system shall
automatically move unavailable Active items to Saved
|
Cart requirements clarify why adding an existing item must combine quantities and why unavailable active items move to saved. section 9.3.1


















