In object-oriented programming, the factory design pattern is one of the most famous design patterns. In this pattern, objects are created without specifying their exact class.
This is achieved by specifying in an interface and implementing by child classes, or, by implementing in a base class and overriding by child classes.
In the class diagram below, the GenerateBill class can not generate a bill directly. Instead, the Factory class generates the correct type of bill using computeBill()
.
public class main {public static void main(String[] arguments) {Factory bill = new Factory();//get an object of Domestic Billing and call its getBill() method.Billing bill_1 = bill.computeBill("Domestic");bill_1.getBill();}}
Free Resources