Creator Mode
A. Definition:
Separates the creation process and representation of a complex object so that different representations can be constructed for the same creation process.
B. Definition Analysis:
" SetComplex objectsThe creation process and representation separation, so that different representations can be constructed for the same creation process. "We assume that an object is very complex, and many components are Pa, Pb, PC, and PD.
" SetComplex objectsOfCreation process and representation SeparationSo that different representations can be constructed for the same creation process. "The interfaces for building and creating are buildpa, buildpb, buildpc, and buildpd, and each part has multiple options of raw materials. the raw material we are talking about, for example, color, is "representation ". the creation process is a call to the buildpx interface, which will never change. the Creator mode allows the process to be separated from the results created for each part, that is, decoupling.
"ReplaceComplex objectsOfCreation process and representation Separation,So that different representations can be constructed for the same creation process. "After decoupling, the same creation process can be expressed differently.
C. Problem
(1) how to decouple it?
Set a director role to organize the builder process. This process will never change.
Class director {
Build_product (){
Builder. buildpa ();
Builder. buildpb ();
Builder. buildpc ();
Builder. buildpd ();
}
};
Builder has four interfaces, such as buildpx, but it is not implemented by itself. Different subclasses represent different representations and assembly methods.
Class builder {
Buildpa ();
Buildpb ();
Buildpc ();
Buildpd ();
};
For example, red color is used when redcolorbuilder builds Pa.
Class redcolorbuilder: Public Builder {
Buildpa ()
{
Setredcolor ();
}
};