Over a million developers have joined DZone.

Quick Design Pattern Review - Abstract Factory

DZone's Guide to

Quick Design Pattern Review - Abstract Factory

· Integration Zone
Free Resource

Migrating from On-Prem to Cloud Middleware? Here’s what Aberdeen Group says leading companies should be considering. Brought to you in partnershp with Liaison Technologies

Need a refresher on Design Patterns? There are plenty of Design Patterns out there. Over the next few months, I plan on writing a bit about most of the common design patterns that can make your life (and mine) as a developer much easier. My aim is to give you just enough of the idea to then be able to research the details from some other resources (some of which I have included).

To start off, I’ll be going through a bunch of Creational Patterns, patterns that are useful when you need to create objects.

Creational Patterns

To start off, let’s talk about the Abstract Factory pattern. The Abstract Factory pattern enables the creation of a set of common objects without having to know the concrete classes themselves.

Abstract Factory

In Java terms, this usually boils down to an abstract class. It is used to create a specific interface that all Factories will agree to. By agreeing to an interface up front, any class that uses one of these Factories doesn't need to know anything about what type of Factory it is really talking to.

What It Can Do for You

From the code, this allows you the ability to swap out Factory types with a single line change. All that is needed is to change the Abstract pointer’s concrete Factory instance. Nothing else needs to be changed.

What It Can’t Do for You

There are a few drawbacks with this design. If you find yourself having to add new types (via new methods) to the Abstract Factory class, you will have to add this same method to all concrete Factory classes as well. This effectively means that all Factories must be modified when any additions are needed.


For more information, including examples, check out these resources:

Is iPaaS solving the right problems? Not knowing the fundamental difference between iPaaS and iPaaS+ could cost you down the road. Brought to you in partnership with Liaison Technologies.


Published at DZone with permission of Isaac Taylor, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}