[Builder in the design mode workout C # series]

zhaozj2021-02-16  47

Name: Builder Chinese Name: Generator Type: Created Description: First I want to say: another similar, a full OOP polymorphism. Good, in a variety of interfaces, it is similar to bridge. There is also a biggest personality: That implementation interface signature is broken down into a multi-step process. Yes, it is here. This way is conducive to the fine control of complex objects (products). Nature, for larger projects, The separation of the processes is also one of the guiding ideas. So, it is integrated: it produces different complex objects (products) through the process handle, and can be used naturally. [C #] // created on 2003 -3-14 AT 10: 13 // Member: // Builder Concretebuilder Director Product

/ * Interface builder {string fook_ (string m_str1); string fook __ (string m_str2); string fook ___ (string m_str3);} * / using system;

Class product_ {public string _str; public product _ () {_str = "product_";}}

class builder {public product_ m_OBJREF; public builder () {m_OBJREF = new product_ ();} virtual public product_ getproduct () {return m_OBJREF;} virtual public void fook _ () {m_OBJREF._str = m_OBJREF._str "bulider_fook_";} Virtual public void fook __ () {m_objref._str = m_objref._str "builder_fook__";} Virtual public void fook ___ () {m_objref._str = m_objref._str "buider_fook__";}}

class concretebuilder1: builder {override public void fook _ () {m_OBJREF._str = m_OBJREF._str "concreatebuilder1_fook_";} override public void fook ___ () {m_OBJREF._str = m_OBJREF._str "concreatebuilder1_fook___";} override public product_ getproduct () { Return M_Objref;}}

class concretebuilder2: builder {override public void fook _ () {m_OBJREF._str = m_OBJREF._str "concreatebuilder2_fook_";} override public void fook ___ () {m_OBJREF._str = m_OBJREF._str "concreatebuilder2_fook___";} override public product_ getproduct () { Return M_Objref;}}

Class Director {public void buildprocess (builder m_objrefprocess) {m_objrefProcess.fook_ (); m_objrefprocess.fook __ (); m_objrefprocess.fook ___ ();}}

class builder_test {public static void Main () {director m_OBJdirector = new director (); concretebuilder1 m_OBJ1 = new concretebuilder1 (); m_OBJdirector.BUILDPROCESS (m_OBJ1); product_ m_OBJproduct_ = m_OBJ1.getproduct (); concretebuilder2 m_OBJ2 = new concretebuilder2 (); m_objdirector.buildprocess (m_obj2); Product_ m_objProduct__ = m_obj2.getProduct (); console.writeLine (m_objProduct_._ Str); console.writeLine (m_objproduct __._ str);}}

Review: 1. When we built Builder, INTERFACE or Abstract Class is not used. It is for the Same Transactor. 2. The Dirctor guides the process. And Dirctor does not know what is produced. This will complete the product. hide.

-------------------------------------------------- ------------------- Declaration: This transit is expected to demonstrate that C # Basic usage does not consider the application of other problems in the actual environment. Such as: multi-thread. Design mode Exercise C # series] Singleton, Bridge ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------

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

New Post(0)