Learning design mode (1) Builder

xiaoxiao2021-03-06  71

(Part of the reference)

http://www.jdon.com/designpatterns/builder.htm

Builder mode definition:

Separation of a complex object is separated from its representation, making the same build process can create different representations.

Because of a complex object, there are not only a lot of components, such as cars, there are many parts: the wheel steering wheel also has a variety of small parts, many parts, but far more than this, how to assemble these parts into a car, this The assembly process is also very complex (requires good assembly technology), and the Builder mode is to separate components and assembly processes.

how to use

Public interface builder {

// Creating a component A such as a car wheel vid buildparta (); // Creating part b, such as creating a car steering wheel void buildpartB (); // Creating a part C, such as creating a car engine void buildingc (); // Return the final assembly result ( Returns the last installed car) // The assembly process of the finished product is not performed here, but is transferred to the Director class below. // thus implementing the decoupling process and component product getResult ();

}

转载请注明原文地址:https://www.9cbs.com/read-93118.html

New Post(0)