Abstraction 00:00:00 Make a prediction You will identify the one operation a caller actually needs and test two implementations against that promise. A reminder only needs to know whether a message was accepted. Should it handle an email socket to send a text notification through a different provider? No. An email socket belongs to one implementation. Ask for a sender operation returning an explicit outcome. The reminder can then use either implementation without understanding how its connection works. 00:00:33 The sledge with three words A child steers a sledge with three instructions: start, slow down and stop. Swapping the runners for a different surface changes the mechanics, but the rider still knows how to stop. Hide the mechanics while preserving what each instruction promises. A stop command that sometimes accelerates would violate the useful abstraction even if its name stayed the same. Abstraction means keeping what matters for a purpose and leaving out the rest. A road map leaves out the trees. A List leaves out the arrays and the pointers. Less to hold in the head. Nobody understands a million lines at once. With abstractions a person works on one level and trusts the level below. 00:01:18 Send without knowing the carrier A reminder wants to send one message and know whether delivery was accepted. It has no reason to know the email server's command sequence. Define a sender operation with a destination and message. Implement the email details behind it. In a test, substitute a sender that records the message and returns accepted. If the reminder still needs an email connection object, the boundary is leaking. Give the reminder a known recipient and an identical message. Email returns accepted; a text provider returns unavailable. A useful abstraction preserves that difference so the caller can decide whether to retry. A method that always says sent merely hides information the workflow needs. 00:02:02 Hide route-finding details A map screen requests a route between two stops and reads its travel time. A small town could use a simple lookup while a large network searches a graph. The route abstraction holds if both return a route or an explicit no-route result under the same rules. Let the map return a route from A to B, then remove the only connection to B. Whether the map searches a table or a graph, it must represent an unreachable destination. Returning an empty route for both already-there and unreachable would make the caller guess at the result. A sender that returns accepted merely because it opened a socket may overstate the contract. Define whether acceptance means queued locally or accepted by the remote service. For a tiny operation whose implementations never vary, a clear function can express the abstraction without introducing a class hierarchy. The Linux virtual file system gives programs a common interface across different file systems. TCP offers another example. The TCP standard promises a reliable, ordered stream of bytes. TCP handles lost packets and reorders segments before delivering those bytes. A delayed packet can still delay the application, so the abstraction does not promise constant latency. 00:03:22 Try an interview follow-up Why several interfaces and only one parent class in Java? Two parents could bring two copies of state and two bodies of one method, and the language would need rules for which one wins. Interfaces have no instance state. Since Java 8 they may have default bodies, so a conflict is possible, and then the class must override the method itself. A cafe needs to issue receipts on paper and by email. Ask what the checkout actually needs to know. It needs to submit a receipt and observe whether delivery was accepted. Printer tray settings and mail server configuration belong behind that boundary. Test the promise with a recording implementation. 00:04:10 What to take with you Abstraction keeps what matters for a caller and hides the rest behind a small contract. Different classes fulfil the contract in their own way, so callers stay simple and insides can be replaced. Write the contract in the caller's words, with failure and limits. Use an interface for an ability and an abstract class for a family that shares code. Test every inside against the same contract, and remove abstractions that stopped paying.