The current code uses a Telescoping Constructor: one constructor that takes every part. As BurgerMeal gains cheese, sauce, or isTakeout, the constructor gets longer and longer, and the code breaks easily.
1. Readability & Parameter Confusion
Issue:new BurgerMeal("wheat", "non-veg", "none", null) is hard to read. You cannot tell what each value means.
Risk: Many parameters are String, so it is easy to swap "wheat" and "non-veg" by mistake. The compiler will not catch this error.
2. The "Forced Argument" Tax
Issue: The client must give a value for every parameter, even for parts they do not want.
Code Smell (a sign of weak design): Passing null or "none" clutters the main method. It also risks a NullPointerException (a crash when code uses a null value).
3. Maintenance Rigidity
Inflexibility: To allow a burger with just bread, you would need a new overloaded constructor (same name, different parameters). This leads to "Constructor Bloat."
Breaking Changes: Adding one new field to the constructor breaks every existing instantiation of BurgerMeal in the entire project.
4. Technical Bug (Type Mismatch)
Error (if you make this mistake):The constructor BurgerMeal(String, String, String, String) is undefined.
Reason: The 4th argument must be a List<String>. Passing "null" (text in quotes) instead of null (no object) gives a type mismatch. The repo's BurgerMealWithoutBuilder.java passes real null, so it compiles, but the burger prints Drinks=null.
1package DesignPatterns.CreationalPatterns.BuilderPattern.Before;23import java.util.List;45/**6 * LEGACY APPROACH: Using a "Telescoping Constructor"7 * This file demonstrates the problems that arise before implementing the Builder Pattern.8 */910class BurgerMeal {1112 private String bread;13 private String patty;14 private String sides;15 private List<String> drinks;1617 // PROBLEM 1: Rigidity18 // If we add 'cheese' or 'sauce', every single call to this constructor across19 // the entire project will break and must be updated.20 public BurgerMeal(21 String bread,22 String patty,23 String sides,24 List<String> drinks25 ) {26 this.bread = bread;27 this.patty = patty;28 this.sides = sides;29 this.drinks = drinks;30 }3132 @Override33 public String toString() {34 return (35 "Burger [Bread=" +36 bread +37 ", Patty=" +38 patty +39 ", Sides=" +40 sides +41 ", Drinks=" +42 drinks +43 "]"44 );45 }46}4748public class BurgerMealWithoutBuilder {4950 public static void main(String[] args) {51 // PROBLEM 2: Readability52 // Looking at the line below, it's hard to tell which String is 'bread' and which is 'sides'53 // without looking at the class definition.5455 // PROBLEM 3: Forced Arguments56 // Even if I don't want sides or drinks, I am forced to pass "none" or null.57 BurgerMeal burgerMeal = new BurgerMeal(58 "wheat",59 "non-veg",60 "none",61 null62 );6364 System.out.println(burgerMeal);65 }66}67