Skip to content
Sharp

Language Upgrades · interview question

In an e-commerce system, a sealed class 'Order' allows only 'OnlineOrder' and 'InStoreOrder' as subclasses. What architectural benefit does this provide?

Multiple choiceHardchapter-12-curatedpremiumlanguage-upgradessealed-classes
Choose one answer
Answer and explanation

Correct answer

D. It restricts order types to those that are known and verified, preventing unauthorized extensions.

Why

By restricting the 'Order' class to only 'OnlineOrder' and 'InStoreOrder', the system ensures that only verified and expected types of orders are processed. This prevents unauthorized or untrusted extensions, maintaining the integrity and security of the order processing logic.

Test yourself on Language Upgrades

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

Start free test
All Language Upgrades questions →