Client code might get error prone and unreadable due to this telescoping constructor anti-pattern. The client may get confused with the large set of parameters and it will be difficult for client code to identify proper meaning and data types to add. Likewise, the smoothie making becomes complex with the number of input parameters. Public class Smoothie ( String milk, String vanilla, String sweetener, String banana, String orange, String dates ) Most customers like to drink chocolate smoothies, so if we take this to the programming world, you have a smoothie class and the class constructor contains the required parameters to make a smoothie, You can buy different kinds of smoothies. In addition, it creates problems in selecting the suitable constructor for the required scenario. Higher parameters lead problems like difficulty in selecting, remembering the correct order, and purpose of each parameter. It is an anti-pattern where the complexity caused due to the increased number of constructor parameters. This may lead to the problem of ‘Telescoping Constructor’ pattern. As a result, the number of constructor parameters increase. Hence, it needs additional input parameters to get the required results. At the same time object might need to take different forms to fulfil client requirements. The object itself may get bulky, and low in modularity.
When the roles and responsibilities get heavier for one object, the creation of that object becomes complex and messy. It is suitable for small systems with lower object dependencies and lesser object representations or sub-classes. This approach leads to the high coupling. In general, we keep the object construction code such as instantiation and initialization within the object as a part of its constructor. Hence, the object can take different forms depending on the applied input parameters. In this case, a separate entity that called the ‘Builder’ do the object creation and the client can use the ‘Builder’ to create an object with any preference. That is different forms can use the same flow of steps to create the objects. In simple words, the process of constructing a complex object should be generic. ‘Separate the construction of a complex object from its representation so that the same construction process can create different representations’ The GOF definition for builder pattern is, This pattern enables the polymorphism by providing an effective solution for creating different forms of an object while using a consistent construction process. The main intention of the builder pattern is to create complex objects by separating the construction process from its representation. Builder pattern is a creational design pattern.