to explore the universe with bits (quite literally) I travel through space time with my Pals - Salesforce, Python, PHP, and NodeJS Salesforce Developer | AI Generalist | System Design Learner Let’s Connect https://www.linkedin.com/in/eduanmoldeep/
wall socket. The house wiring doesn't care what you plug in, as long as it fits the socket. The Wall Socket Interface): Defines the shape and voltage The Contract). The Device Implementation): A lamp, a laptop, or a vacuum can plug in The Implementation).
to switch to a LinkedList for performance later, you have to rewrite the Service code. Loose Coupling Good You can swap new ArrayList() with new LinkedList() or new Vector() without breaking the rest of the code. public class // Hard dependency on ArrayList private new public class // Coding to the Interface private new
to MongoDB) if your Service only talks to a generic Repository interface. Testability Interfaces allow you to inject "Mock" objects during testing. You can't mock a tightly coupled new object easily. Maintainability Changes in the implementation details don't ripple out and break other parts of the system.
broke the contract. • Rule 1 If a.equals(b) is true, then a.hashCode() MUST be equal to b.hashCode(). • Rule 2 If hashCodes are different, the objects are definitely different. • The Bug: If you override equals but not hashCode, your object gets lost in the HashMap buckets.
declared Use Case: Recoverable errors. "The file is missing, ask user for a new path." Pros: Forces developers to handle failure. Cons: Can clutter code Boilerplate). Unchecked Runtime) // Silent failure unless caught Use Case: Logic errors. "NullPointerException", "IndexOutOfBounds". Modern Trend: Spring and modern frameworks prefer Unchecked exceptions to keep code clean.
Works with any class implementing AutoCloseable. new "path" try // usage finally if null // What if close() throws? // Auto-closes even if error occurs try new "path" // usage
factory assembly line. 1. Source: The raw materials List, Set). 2. Intermediate Ops: The machines Filter, Map, Sort). These are lazy. Nothing happens until... 3 . Terminal Op: The packaging Collect, Count, ForEach). This triggers the flow.
→ String, String] Input: Stream Output: Stream flatMap() One-to-Many Flattening). A, B, C → A, B, C Use Case: You have a List of Orders, and each Order has a List of Items. You want one big stream of all Items.
database without touching the Controller, or change the API format without touching the Database. • Controller: Handling HTTP Req/Res). NO business logic here. • Service: The Brains. Transactional business logic. • Repository: Data Access. Talking to DB.
Entity (e.g., User with password field) directly to the API consumer is a security risk and creates tight coupling. The Solution Create a separate POJO (e.g., UserDTO) that contains only the fields you want to show. DTO Entit y
controller method with try-catch blocks. Use AOP Aspect Oriented Programming) to handle errors globally. @RestControllerAdvice public class @ExceptionHandler public return "Not Found"
Hides dependencies, hard to test NullPointer in unit tests). Setter Injection Okay. Good for optional dependencies, but allows mutable state. Constructor Injection Best. Ensures object is fully initialized. Easy to pass Mocks in tests.