Design 103 : Why do we need Abstract Factory Pattern now?

public abstract Class PizzaStore {    
Public Pizza OrderPizza(String type)
{
Pizza pizza = createPizza(type);

pizza.prepare();
pizza.bake();
pizza.cut();
pizza.box();
return pizza;
}

Protected abstract Pizza createPizza(String type);
}
// Cannot inherit from some other base class if required.
public Class IndianPizzaStore extends PizzaStore {
@override
Protected Pizza createPizza(String type) {
//..
}
}
public abstract Class PizzaStore {    
Public Pizza OrderPizza(String type)
{
Pizza pizza = createPizza(type);

pizza.prepare();
pizza.bake();
pizza.cut();
pizza.box();
return pizza;
}
Protected abstract Pizza createPizza(String type);
}
public Class PizzaStore extends WhateverWeWant {    // switch it up at runtime with any factory you want!
private PizzaFactory factory;

public PizzaStore(PizzaFactory factory) {
this.factory = factory;
}
Public Pizza OrderPizza(String type) {
Pizza pizza = factory.createPizza(type);
pizza.prepare();
pizza.bake();
pizza.cut();
pizza.box();
return pizza;
}
}
Public Interface PizzaFactory {
Pizza createPizza(String type);
}
Public IndianPizzaFactory implements Pizzafactory { Pizza createPizza(String type) {
//..
}
}

--

--

--

Cooking Dreams | Engineering at Disney+ Hotstar Github.Handle:https://github.com/LuGO0

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

PYTHON VS JAVA-Which Language to Choose for your Application?

Top .NET Libraries You Should Know

Salesforce deployment approach from scratch in 2021

Application Lifecycle management of salesforce

Linus Torvalds And His Penguin(s)

Web performance investigative techniques

How to handle a University project?

Step-by-Step Guide to Creating an A-Worthy Synthesis Essay Example

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Saurabh Kumar

Saurabh Kumar

Cooking Dreams | Engineering at Disney+ Hotstar Github.Handle:https://github.com/LuGO0

More from Medium

Design 102 : Why do we need Factory Method Pattern?

Is Java dying ? .. maybe not!!

Basic OOP for shavetail Louies — PART III [Inheritance | Composition | Encapsulation]

3 Essentials for long-running batch jobs