🏛️ Design Principles & Patterns
16 Java concepts, each explained step by step with real code, a common trap and practice questions.
- Single ResponsibilityOne reason to change.
- Open/ClosedOpen for extension, closed for modification.
- Interface Segregation & Dependency InversionSmall interfaces; depend on abstractions.
- SingletonLazy holder, enum singleton, double-checked locking with volatile, why it hurts testing.
- Factory & static factory methodsNamed constructors, hiding implementation classes.
- BuilderReadable construction of objects with many optional parameters.
- StrategySwappable algorithms, often as lambdas.
- ObserverPublish-subscribe and listener leaks.
- Decorator & ProxyWrapping to add behavior (java.io streams) vs controlling access.
- Adapter & FacadeConverting interfaces; simplifying subsystems.
- Template Method & CommandFixed skeleton with overridable steps; actions as objects.
- State & Chain of ResponsibilityBehavior by state objects; handlers passing requests along.
- Composite & IteratorTree structures treated uniformly; traversal abstraction.
- Dependency InjectionConstructor injection, inversion of control, testability.
- Effective Java essentialsMinimize mutability, defensive copies, prefer interfaces, avoid finalizers, design for inheritance or prohibit it.
- Clean code in JavaNaming, small methods, avoiding nulls, meaningful exceptions.