CSE Roadmap

Core tier · about 2 hours · 7 parts

Part 2 of 7 · 1 min read

Hiding the inside

A component shows an API and keeps the rest private.

A vending machine shows buttons and a slot. It does not let customers reach in and move the coins. EJ says the most important difference between a well-designed component and a poor one is how well it hides its internal data and details. A good component cleanly separates its API from its implementation, and other components talk to it only through the API. This idea is called information hiding or encapsulation.

EJ lists the benefits. Hidden parts decouple components, so each can be developed, tested, optimised, understood and changed alone. Maintenance is easier because a component can be debugged or replaced with little fear of harming others. Components that are not tightly coupled often prove useful in other contexts. And hiding enables performance tuning: once profiling finds the slow part, it can be changed without touching the rest.

Encapsulation

Encapsulation is hiding an object's data and details behind a small set of methods, so that other code depends only on what the object does and not on how it does it.

Example: callers ask a BookingService to book a room. They cannot see or reorder its internal list of bookings.

Check yourself: 1. What does EJ say separates a good component from a poor one? 2. Name two benefits of hiding details. 3. What stays visible in an encapsulated class?