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,

  • What's problem if I pass all parts to constructor? – gotrongluan Jul 21 '20 at 08:56
  • What's problem if I use another method (e.g createSomeInstance) in class, and that method will create object step by step? – gotrongluan Jul 21 '20 at 08:56
  • what if there are optional parts? why adding them to the mandatory constructor? what if some parts should be entered before other parts? – Ori Marko Jul 21 '20 at 09: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) – gotrongluan Jul 21 '20 at 09:54

0 Answers0