Vending Machine :

In this example , the abstract factory design pattern is used to accessed different beverages (products) using the FactoryProducer object.

In the main method of the Demo class, HotDrinkFactory and ColdDrinkFactory classes are instantiated. The getProduct method of ProductFactory interface is called by passing BeverageType parameter. In return related Product (BlackCoffee, Cappuccino, Lemonade, HotMilk, or CocaCola) object is created. Later, the Product object’s make method is called in the main method of the Demo class.

The generated java code of the vending machine case study is below.

Abstract-2.pdf