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 (154)
  • 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)
  • spring-boot (36)
  • Systems Thinking (3)
  • GitHub Weekly: MCP Tools Trending Right Now (September 28 – October 4, 2026)
  • The Bulkhead Pattern: Why One Slow Dependency Shouldn’t Sink the Whole Ship
  • Essential Reading: A Philosophy of Software Design — Fighting Complexity One Module at a Time
  • GitHub Weekly: Top 10 Trending Repos (September 21 – September 27, 2026)
  • The Volunteer Tax: Why Raising Your Hand in a Meeting Makes You the Permanent Owner
©2026 José da Cruz | WordPress Theme by SuperbThemes