Design Patterns – Builder pattern

Problem Statement : How do we solve problem related to complex object creation like too Many arguments to pass, some of the parameters might be optional and the object is heavy and its creation is complex ?

Solution : Builder design pattern is used to construct objects such that they can be decoupled from the implementing system

  • It solves the issue with large number of optional parameters and inconsistent state by providing a way to build the object step-by-step and provide a method that will return the final Object
  • The parameters to the constructor are reduced and are provided in highly readable method calls.
  • It also helps in minimizing the number of parameters in constructor and thus there is no need to pass in null for optional parameters to the constructor.
  • Object is always instantiated in a complete state

Immutable objects can be built without much complex logic in object building process

Examples: All implementations of java.lang.Appendable, java.lang.StringBuilder & java.lang.StringBuffer

Good one Vinit , easy to understand. Keep up the good work

Like
Reply

To view or add a comment, sign in

More articles by Vinit Goyal

  • Visitor Pattern

    An overview on visitor pattern. Problem Statement : When we have large object hierarchies, where adding a new…

    1 Comment
  • Event Management - Apache Kafka

    Apache Kafka is fast, scalable, durable and fault tolerant publish-subscribe messaging system best suited for scenarios…

    4 Comments
  • In Memory Database - Redis Caching

    Redis is an in memory, key-value database. It has the ability to store and manipulate high level data types.

    4 Comments

Explore content categories