A shopping cart. This is essentially a specialized Bag: you can #add: or #remove: WAStoreItems to it, and calculate their #totalPrice. You can also use #countsAndItems to get a collection of associations between the items and the number of times they appear in the cart, useful for summary displays.
ProtoObjectObjectWAStoreCart
| items |
| instance | class |
|---|---|
| as yet unclassified | no messages
|
| items |
|---|
|
| as yet unclassified |
|---|
| add: anObject |
items ifNil: [items _ Bag new]. items add: anObject |
| countsAndItems |
^ items sortedCounts |
| hasItems |
^ items notNil and: [items isEmpty not] |
| items |
^ items |
| remove: anObject |
items remove: anObject ifAbsent: [] |
| totalPrice |
^ items detectSum: [:ea | ea price] |