Day5 of #100DaysOfCode Challenge: Factory Pattern in Java

In programming, Factory Pattern can be describe as object builder and one of the best example for this is Vehicle Factory were we will build a vehicle according to ordered type.


Step 1: Create your abstract Vehicle class and define its properties. You can also use Interface.

Step 2: Create Car vehicle class

Step 3: Create your Van vehicle class

Step 4: Create your Truck vehicle class

Step 5: Create your vehicle Factory class.

Step 7: Finally, test your Factory.

the example will output:
CAR price is 600.0
VAN price is 500.0
TRUCK price is 400.0
BICYCLE price is 300.0

Leave a Reply

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