O'Reilly logo

Spring 5 Design Patterns by Dinesh Rajput

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sample implementation of the Abstract Factory design pattern

I am going to create a Bank and Account interface and some concrete classes implementing these interfaces. Here, I also create an abstract factory class, AbstractFactory. I have some factory classes, BankFactory and AccountFactory; these classes extend the AbstractFactory class. I will also create a FactoryProducer class to create the factories.

Let's see this design pattern in the following image:

UML diagram for the Abstract Factory design pattern

Create a demo class, AbstractFactoryPatternMain; it uses FactoryProducer to get an AbstractFactory object. Here, I pass information ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required