0

I read about Builder Design Pattern on this wikipedia link and it tells that

Creating and assembling the parts of a complex object directly within a class is inflexible. It commits the class to creating a particular representation of the complex object and makes it impossible to change the representation later independently from (without having to change) the class.

I don't undestand why create and assembs directly in class is inflexible? With different representation I can add different method for class, why it's not good?

Thanks for all help,

4
  • What's problem if I pass all parts to constructor? Commented Jul 21, 2020 at 8:56
  • What's problem if I use another method (e.g createSomeInstance) in class, and that method will create object step by step? Commented Jul 21, 2020 at 8:56
  • what if there are optional parts? why adding them to the mandatory constructor? what if some parts should be entered before other parts? Commented Jul 21, 2020 at 9:30
  • No, it isn't. In constructor we can use optional arguments. If some parts should be entered before other parts, we can do in constructor. Just move logic code of creating object from builder to the constructor of class (or extra method - which responsible for build object) Commented Jul 21, 2020 at 9:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.