Skip to content
Sharp

Object-oriented programming · interview question

Which pattern should be used to ensure that a Product's price does not fall below a minimum allowable value?

Multiple choiceHardchapter-3-curatedpremiumoopobject-responsibility
Choose one answer
Answer and explanation

Correct answer

C. Validation within the Product class

Why

Validation logic should reside within the Product class as it owns the price field. This ensures that any changes to the price are validated immediately and consistently, maintaining the integrity of the Product object.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →