Skip to content
José da Cruz

Enterprise Architect, and Life Thinker

José da Cruz

Enterprise Architect, and Life Thinker

Pattern – Abstract Factory

josedacruz, November 4, 2024November 4, 2024

Pattern – Abstract Factory

What: Provides an interface for creating families of related or dependent objects without specifying their concrete classes.

Best use case: When you need to create families of objects that work together, like UI elements for different platforms.

Diagram

Abstract Factory Class Diagram

How it works:

  • Abstract Factory Interface (DAOFactory):
    • Defines a common interface for creating different types of DAOs (ProductDAO and UserDAO).
  • Concrete Factory Classes (MySQLDAOFactory, PostgreSQLDAOFactory):
    • Implement the DAOFactory interface.
    • Create concrete DAO objects (MySQLProductDAO, MySQLUserDAO, PostgreSQLProductDAO, PostgreSQLUserDAO) specific to the database system.
  • Abstract Product Interfaces (ProductDAO, UserDAO):
    • Define the common interface for database operations on products and users.
  • Concrete Product Classes (MySQLProductDAO, MySQLUserDAO, PostgreSQLProductDAO, PostgreSQLUserDAO):
    • Implement the corresponding abstract product interface.
    • Provide database-specific implementations for the operations.

By using the Abstract Factory pattern, you can easily switch between different database systems without modifying the core application logic. You simply need to change the concrete factory implementation to create DAOs for the desired database. This promotes loose coupling, flexibility, and testability in your application.

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