Don't Use Getters/Setters/Properties
Tell, don't ask β instead of getting data to make decisions outside the object, tell the object what to do and let it use its own data.
Why this matters
Getters and setters are public fields wearing a disguise. When the caller reads the balance, adds to it, and writes it back, the business rule (the deposit amount must be positive, the balance must never go negative) is scattered across every call site. When the object owns that rule entirely β via a deposit() method β you can never break it from outside. This is the core of the "Tell, Don't Ask" principle.
Code Challenge
Study the messy code, try to refactor it, then reveal the clean version.
π‘Key takeaway
Replace getters and setters with methods that describe intent β deposit(), withdraw(), promote(). Business rules live inside the object and can never be bypassed from outside.
π§ Some exercises may still have errors. If something seems wrong, use the Feedback button (bottom-right of the page) to report it β it helps us fix it fast.
Hint: Every getter that feeds an if-statement is a behavior that belongs inside the object being interrogated.
β Your version