Builder

motivation

  • In software systems, sometimes faced with the creation of "a complex object", which is usually composed of sub-objects of various parts with a certain algorithm; due to changes in requirements, various parts of this complex object often face drastic changes. But the algorithm that combines them is relatively stable.
  • How to deal with this change? How to provide an encapsulation mechanism to "isolate the changes of "all parts of complex objects" so as to keep the "stable construction algorithm" in the system from changing with changes in demand?

Mode definition

  • Separate the construction of a complex object from its representation, so that the same construction process (stable) can create different representations (variations).

Summary of main points

  • The Builder mode is mainly used to "build a complex object step by step". Among them, "step by step" is a stable algorithm, and various parts of complex objects often change.
  • Where is the point of change, and where is the package—Builder mode is mainly to cope with frequent changes in requirements of "each part of a complex object". The disadvantage is that it is difficult to cope with the changes in the demand for "step-by-step algorithm construction".
  • In the Builder mode, pay attention to the difference in calling virtual functions in the constructor in different languages ​​(C++, C#)

Guess you like

Origin blog.csdn.net/oTianLe1234/article/details/113835056