Encapsulation Builder
Protect the Cave Map
Keep the map private inside an Explorer Backpack. Use methods as the only safe way to pack or read it.
Builder idea:
#map is protected data. packMap() and readMap() are trusted doors that control it.
Choose a method, then run it.
class ExplorerBackpack {
#map = "treasure map";
packMap() { /* protect it */ }
readMap() { /* safely use it */ }
}
Pack map
Read map
Block shortcut
The backpack controls its own map.
Complete all three tests to prove the map is encapsulated.
Encapsulation builder complete!
The map stayed protected, while its methods provided safe ways to store and use it.
Completed! Try Encapsulation Challenge