Skip to content

curious-aman/design-patterns

Repository files navigation

Design-patterns

Creational design patterns

  1. Singleton Pattern
  2. Builder Pattern
  3. ProtoType Pattern
  4. Factory Method pattern
  5. Abstract Factory Pattern

3. Prototype pattern

3.1 Overview

  • AVoids costly creation
  • Avoids subclassing
  • Typically doesn't use new
  • Often utilizes an Interface
  • Usually implemented with a Registry
  • Example:
    • java.lang.Object#clone()

3.2 pitfalls

  • Sometimes not clear when to use
  • Used with other patterns
  • SHallow copy only

4. Factory Method pattern

4.1 Overview

  • Doesn't expose instantiation logic
  • Defer to subclass
  • Common interface
  • Specified by architecture, implemented by user
  • Example:
    • Calendar
    • ResourceBundle
    • NumberFormat
Design

Factory is responsible for lifecycle
Common Interface
Concrete Classes
Parameterized create method

4.2 pitfalls

  • Complexity, need to write a lot of code
  • Refactoring is not possible

5. Abstract Factory pattern

5.1 Overview

  • Factory of Factories
  • Factory of related objects
  • Common interface
  • Defer to subclass
  • Example:
    • DocumentBuilder
Design

Group Factories together
Factory is responsible for lifecycle
Common Interface
Concrete Classes
Parameterized create method
Build using composition

5.2 pitfalls

  • Complexity, need to write a lot of code
  • Refactoring is not possible

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages