Activity 01
Pair Programming: Broken vs Protected Class
Pairs code a simple Inventory class first with public fields, allowing invalid changes like negative stock. Then refactor to private fields with getter/setter methods and validation. Partners test each version and discuss differences in reliability.
Why is it important to hide the internal implementation details of a class?
Facilitation TipIn Pair Programming: Broken vs Protected Class, ask one partner to try accessing private fields directly while the other explains the compile error to reinforce the concept.
What to look forPresent students with short code snippets. Ask them to identify which members are public and which are private, and to explain why a particular access attempt would result in an error. For example: 'In this `Car` class, why can we directly change `car.speed` but not `car.engineStatus'?