• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Abhishek Tanwar

I build web & mobile experiences

  • HOME
  • BLOG
  • CONTACT ME
  • DISCLAIMER & COPYRIGHTS
You are here: Home / Uncategorized / Creational Pattern | Abstract Factory

Creational Pattern | Abstract Factory

August 24, 2013 by Abhishek Tanwar

Now a days, design pattern are treated as a complex architecture patterns where it is thought that it is accessible and understandable to only experienced developers or designers. NOT TRUE. If you understand the basic concepts of any Object Oriented Programming, you can understand and implement any of the design patterns.

Lets start with Creational Pattern | Abstract Factory Pattern.

Objective of this pattern is to provide only a way to create related objects. Let’s take a closer look.

Implementation

Lets assume that you own an Alienware Gaming laptop modelling house. You provide the best gaming laptop and offer two models M14 and M17.

My 2 favourite locations are Paris and Amsterdam. So lets assume that we provide the products assembled at those locations only.

DP_AbstractFactory_1

 

In the above picture, left, we have the factory where we have two products M14 and M17 which are delivered in the two locations (Paris,Amsterdam). This is just provide the interface. The actual configuration and delivery process is hidden here. This will be there in the Actual Product and Assembling Implementations only.

You can specify any specific process for any product in any location without the need to changing anything in abstract layer.

Lets start with working example. As I already explained the scenario above, I have created a sample project for this pattern which you can download using the link at the bottom.

The project hierarchy is as below:

0

 

Now, lets look at the first class which is “AbstrackAlienwareM14”. this class is an abstract class for AlienwareM14 models which can be increasing in future as we all know you, me and lot others like Alienware.

The basic methods for M14 are “getConfigurations” and “preloadedApps”. The implementation of such methods will be in actual concrete implementations.

1

Now this is the actual concrete implementation of M14 Alienware model. This implements the two operations required for M14. I have put some logic based on Delivery location about the specification as I have experienced the same.

2

This is a similar implementation for M14 as above.

3

This is the abstract class for M17 which can be used for other upcoming new models of M17 Alienware class.

4

Now, lets get started with the usage of these all aliens we have created. I am created a very basic Factory “AlienFactory” which will just let you order Alienware 14 or 17 models for real! “Just Kidding”.

5

This is an implementation of the AlienFactory based on location. As in our example we have two locations I have created below two concrete implementations of the Factory – Paris and Amsterdam.

6

7

Finally the complete pattern design is in place now. Now the actual client side implementation of using the pattern that we have created.

Below is the code to order M14 or M17 in both the locations.

89

We have observed that the definition interface is kept separate from the actual implementation of those interfaces. In this context how the laptops gets delivered in various locations is separate from the product configuration and delivery.

This is very basic pattern and is used most often in creating libraries and helper objects. If implemented efficiently, this pattern can bring lot of code re-usability to any application.

Hope this helped you understand the pattern better.

For your reference, I have implemented the above example using JAVA. Have a look HERE.

Share this:

  • Facebook
  • X

Like this:

Like Loading...

Filed Under: Uncategorized Tagged With: Abstract Factory, Design Patterns

Reader Interactions

Trackbacks

  1. Creational Pattern | Builder | Raving About Technology says:
    September 18, 2013 at 1:39 pm

    […] is the second pattern that I am going to discuss after Abstract Factory. Now, if you have read the description of this pattern, you will feel like it is similar to […]

Primary Sidebar

  • Behance
  • Email
  • Facebook
  • GitHub
  • LinkedIn

Popular Posts

How To Integrate React in JSP Application
SaaS, PaaS, IaaS
XQuery highlighting in Notepad++
Standard Design Patterns – Applied to JAVA
XQDT Installation on Eclipse JUNO

Categories

  • Building APIs
  • Building Mobile Apps
  • Building Web Apps
  • Coding Challenges
  • Extensions
  • Fullstack
  • Patterns
  • Tips & Tricks
  • Uncategorized
  • VSCode

Tags

2022 vscode extensions Abstract Factory alienware amazing vscode extensions apple challenges coding coding-challenges Design Patterns dota2 dota2 items dynamic web service call dynamic webservice invocation enterprise integration express flex helpful vscode extensions how to implement mfa in nodejs increasing productivity using vscode integration pattern macro message channel message endpoint message pattern message router message translator messaging mfa offline action processing offline actions in struts pipes and filters PRG in struts react Steam struts System Emulator threads in struts utilities vscode vscode customization vscode extensions vscode productivity extensions xquery xquery 1.0 xquery design principles

Recent Posts

  • 15+ VSCode Extensions To Improve Your Productivity
  • Productivity and Quality Extensions for ReactJS in VSCode..
  • My goto VSCode plugins for 2022…
  • How to enable MFA for your application in Node.JS?
  • Structuring Express Application – How I do it?

Categories

  • Building APIs (8)
  • Building Mobile Apps (1)
  • Building Web Apps (7)
  • Coding Challenges (3)
  • Extensions (1)
  • Fullstack (6)
  • Patterns (8)
  • Tips & Tricks (41)
  • Uncategorized (43)
  • VSCode (2)

Tags

2022 vscode extensions Abstract Factory alienware amazing vscode extensions apple challenges coding coding-challenges Design Patterns dota2 dota2 items dynamic web service call dynamic webservice invocation enterprise integration express flex helpful vscode extensions how to implement mfa in nodejs increasing productivity using vscode integration pattern macro message channel message endpoint message pattern message router message translator messaging mfa offline action processing offline actions in struts pipes and filters PRG in struts react Steam struts System Emulator threads in struts utilities vscode vscode customization vscode extensions vscode productivity extensions xquery xquery 1.0 xquery design principles

Archives

  • August 2023 (1)
  • March 2022 (1)
  • February 2022 (1)
  • November 2020 (1)
  • April 2020 (2)
  • May 2019 (1)
  • April 2019 (1)
  • March 2019 (1)
  • December 2018 (1)
  • July 2018 (4)
  • June 2018 (3)
  • March 2018 (1)
  • May 2016 (1)
  • December 2015 (1)
  • May 2015 (1)
  • April 2015 (2)
  • March 2015 (1)
  • December 2014 (2)
  • November 2014 (2)
  • October 2014 (1)
  • August 2014 (2)
  • July 2014 (1)
  • April 2014 (1)
  • March 2014 (1)
  • February 2014 (2)
  • January 2014 (1)
  • December 2013 (4)
  • November 2013 (4)
  • October 2013 (3)
  • September 2013 (4)
  • August 2013 (2)
  • July 2013 (5)
  • June 2013 (9)
  • May 2013 (6)
  • April 2013 (2)
  • March 2013 (2)
  • January 2013 (1)
  • November 2012 (2)
  • HOME
  • BLOG
  • CONTACT ME
  • DISCLAIMER & COPYRIGHTS

Copyright © 2025

%d