World 24 of 26 · Advanced

🏛️ Design Principles & Patterns

16 Java concepts, each explained step by step with real code, a common trap and practice questions.

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