Clearing doubts about the builder pattern

后端 未结 8 1112
攒了一身酷
攒了一身酷 2020-12-28 22:57

I am learning about the builder pattern, and so far I understood that, it is a great alternative to the commonly patterns used for initialization:

  • Telescopi

8条回答
  •  攒了一身酷
    2020-12-28 22:58

    Here are Builder collaborations from GoF book: Collaborations 1. The client creates the Director object and configures it with the desired Builder object. 2. Director notifies the builder whenever a part of the product should be built. 3. Builder handles requests from the director and adds parts to the product. 3. The client retrieves the product from the builder.

    The Builder pattern focuses on constructing a complex object step by step. Builder returns the product as a final step. The returned class in absence of the setters may be as good as immutable. With setters, it can be modified. And inner classes help mask the details.

    Another point worth noting is that a major motivation behind creational design patterns is that the client doesn't worry about creating the product. The object creation process is delegated to factory, builder, etc. The client doesn't have to worry about object creation. It will specify what it wants and will get it as a result of delegated creation process.

提交回复
热议问题