Activity 01
Refactoring Challenge: Fix the Broken Class
Provide a deliberately poorly encapsulated class (e.g., a BankAccount with all public fields). Students identify the design problems, predict what could go wrong if external code modifies the balance directly, then refactor the class to use private fields and appropriate methods. Pairs compare their refactored versions and discuss trade-offs.
Explain how abstraction simplifies complex systems by focusing on essential features.
Facilitation TipDuring the Refactoring Challenge, circulate and ask guiding questions like 'What would break if this field were public?' to push students beyond surface-level fixes.
What to look forPresent students with a simple class definition (e.g., a 'BankAccount' class with private balance and public deposit/withdraw methods). Ask them to write down which parts are part of the abstraction and which are encapsulated details. Then, ask them to explain why the balance should be private.