Skip to content
José da Cruz

Enterprise Architect, and Life Thinker

José da Cruz

Enterprise Architect, and Life Thinker

Patterns – Factory Method

josedacruz, November 4, 2024November 4, 2024

Pattern – Factory Method

What: Provides an interface for creating objects, but lets subclasses decide which class to instantiate.

Best use case: When you need to create families of related objects without specifying their concrete classes.

Class Diagram for Factory Method

How it works:

  1. The Client class requests a document from the DocumentFactory by specifying the desired document type (e.g., “PDF” or “Word”).
  2. The DocumentFactory uses a conditional statement or a configuration file to determine which concrete Document class to instantiate based on the given type.
  3. The DocumentFactory creates the appropriate document object and returns it to the Client.
  4. The Client can then call the print() method on the returned document object to generate the desired output.

This pattern promotes loose coupling between the client and the concrete product classes. The client doesn’t need to know the specific implementations of the Document classes. It simply interacts with the DocumentFactory to obtain the desired document.

Related

architecture architecturepatterns

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • architecture (167)
  • artificial-intelligence (6)
  • books (2)
  • courses (4)
  • decision-frameworks (4)
  • finances (1)
  • java (8)
  • life-improvement (20)
  • metrics (3)
  • observability (2)
  • puzzles and challenges (3)
  • reviews (1)
  • security (8)
  • Soft Skills (1)
  • spring-boot (36)
  • Systems Thinking (3)
  • GitHub Weekly: AI Agent Tools Trending Right Now (November 2 – November 8, 2026)
  • Designing a Distributed Session Store: Why Sticky Sessions Break Under Load
  • Essential Reading: Release It! — Why Production Is a Different Game Than Development
  • GitHub Weekly: Top 10 Trending Repos (October 26 – November 1, 2026)
  • GitHub Weekly: Architecture & Infra Tools Worth a Look (October 19 – October 25, 2026)
©2026 José da Cruz | WordPress Theme by SuperbThemes