Builder pattern builds a simple object using difficult substance and using a step by step move towards. This type of design pattern comes under creational pattern as this pattern provides one of the best ways to make an object.
A Builder class builds the ultimate object step by step. This builder is dependent of other substance.
We have careful a business case of fast-food café where a typical meal could be a burger and a cold drink. Burger could be each a Vega Burger or Chicken Burger and will be packed by a packaging. Cold drink could be each a coke or Pepsi and will be packed in a bottle.
We are going to generate an Item interface representative food items such as burgers and cold drinks and real classes implementing the Item interface and a Packing interface representing packaging of food items and concrete classes implementing the Packing interface as burger would be packed in wrapper and cold drink would be packed as bottle.
We then construct a Meal class having Array List of Item and a Meal Builder to build altered types of Meal objects by combining Item. BuilderPatternDemo, our demo class will use Meal Builder to build a Meal.
Create an interface Item representing food item and packing.
Create concrete classes implementing the Packing interface.
Create abstract classes implementing the item interface provide default functionalities.
Create concrete classes extending Burger and Cold Drink classes.
Create a Meal class having Item objects defined above.
Create a Meal Builder class, the concrete builder class responsible to generate Meal objects.
BuiderPatternDemo uses MealBuider to display builder pattern.
Verify the output.
Design Patterns Related Interview Questions
|Java Script Interview Questions||AJAX Interview Questions|
|Graphic Design Interview Questions||Adobe Indesign Interview Questions|
|Java-Multithreading Interview Questions||Database Design Interview Questions|
|Compiler Design Interview Questions||CSS Advanced Interview Questions|
|Java Design Patterns Interview Questions||Hardware design Interview Questions|
|Material Design Lite Interview Questions||Object Oriented Analysis and Design Interview Questions|
|Standard Template Library (STL) Interview Questions|
Design Patterns Tutorial
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.