Skip to content
Sharp

Object-oriented programming · interview question

A product can appear in many carts with different quantities. Where does the quantity for one cart line belong most naturally?

Multiple choiceMediumchapter-2-curatedpremiumoopfields-and-state
Choose one answer
Answer and explanation

Correct answer

D. In CartItem, because it belongs to one product-plus-quantity relationship

Why

Quantity for one specific cart line is not universal product state. It belongs to the cart-item relationship, which is why a CartItem object is a better model than scattering quantity across unrelated places.

Test yourself on Object-oriented programming

A free test with instant, explained results. No account needed.

Start free test
All Object-oriented programming questions →