Private Fields and Accessors
Talk it through with a coach who asks guiding questions and gives hints until you reach the answer. Pass to mark the challenge as completed.
The problem
- medium
- Pro
A shopping cart class exposes its items array, and other code keeps pushing to it directly, skipping the cart's validation. Explain how you'd protect the cart's data, using private fields, getters and setters.
Talk this problem through with an AI coach
This is a Pro challenge. Sign in with Google, then upgrade to start a voice session.