Design Patterns

Popular Design Patterns

Important

  • Singleton (multi-threading is important)
  • Factory
  • Abstract Factory
  • Observer
  • Builder

Other

  • Decorator
  • Adapter
  • Strategy
  • Facade

Practical Design Patterns

  • Singleton
    • property: global access + must have only one instance (hurts flexibility)
    • No true example able to find!! possibly anti-pattern.
    • pseudo examples:
      • logger object (they are flexible hence not singleton)
      • Java Beans (they are restricted to each application context hence not really single instance)
  • Builder
    • Lombok’s @Builder annotation
  • Decorator (aka Wrapper, Adapter Pattern is also known as Wrapper)
    • java.util.Collections.unmodifiableList(List)
      • convert list to unmodifiable list
  • Facade
    • Importing libraries
    • SLF4J, JPA??
  • Iterator
    • Interface: java.util.Iterator
      • hasNext(): boolean
      • next(): E
    • For-Each loops use Iterator under the hood for Collections
  • Observer/Reactor for Project Reactor