Java Design Pattern – Abstract Factory Pattern

Abstract factory pattern is a Super-Factory of a group familiar factories. We can use it to expose API for integration code and hidden the logic implementation. Abstract Factory gives us a way to manage and decouple design in case Program has more than one Factory having the same Interface.

The tutorial will guide you a sample for how to program with Abstract Factory Pattern.

I. Technology

-Java 8
– Eclipse: Version: Mars.2 Release (4.5.2)

II. Overview – Abstract Factory Pattern

– Program has a MobileFactory interface that define API. SamsungFactory and AppleFactory are 2 classes that implement Mobile Factory.
– Product includes: SmartPhone & Table. AppleFactory produces: Iphone6, IPhone6Plus, IPadPro, IPadMini4. SamsungFactory produces: GalaxyJ7, GalaxyOn7, GalaxyTabA, GalaxyTabS2.

– Class Diagram

java design pattern - abstract factory pattern uml

– Project Structure:
java design pattern abstract factory project structure

1. Create Product API

– SmartPhone interface

– Define SmartPhone List

– Tablet interface

– Define Tablet List

2. Create Smart Phone Product Concrete class

SmartPhone products:

– Iphone6

– Iphone 6 Plus:

– GalaxyJ7:

– GalaxyOn7

3. Create Table product

– IPad Pro

– IPadMini4

– GalaxyTabA

– GalaxyTabS2

3. Create Mobile Factory Interface

– Define Mobile Factory List

4. Implement Abstract Mobile Factory

Create 2 Mobile Factory
– Implement AppleFactory

-Implement Samsung Mobile Factory

5. Create Mobile Factory Producer& Implement Main Class

– Main Class

IV. Result

V. Source Code


By grokonez | October 15, 2016.

Last updated on June 4, 2017.

Related Posts

Got Something To Say:

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