Code example of the builder mode of the Design Pattern

Source: Internet
Author: User
using System;using System.Collections;using System.Collections.Generic;namespace BuilderFunc{    public class Product{        List<string> arrList = new List<string>();        // First in First Out (FIFO)         Queue  Q = new Queue();                 // Last in First out (LIFO)         Stack S = new Stack();        public void Add(string param)        {            arrList.Add(param);        }        public void AddEvent(EventArgs e)        {            Q.Enqueue(e);        }                public void Show() {             Console.WriteLine("\nProduct Param -------");             foreach (string part in arrList)                 Console.WriteLine(part);                             foreach (EventArgs e in Q)                 Console.WriteLine(e);         }    }    public abstract class AbstractBuilder{        public abstract void BuilderProductA();        public abstract void BuilderProductB();        public abstract Product GetResult();    }    public class ConcreteBuilder1 : AbstractBuilder{        private Product product = new Product();        public override void BuilderProductA(){            product.Add(this.ToString() + " : BuilderProductA");        }        public override void BuilderProductB(){            product.Add(this.ToString() + " : BuilderProductB");        }        public override Product GetResult(){            return product;        }    }    public class Director{        public static void CreateBuilder(AbstractBuilder abstractBuilder)        {            abstractBuilder.BuilderProductA();            abstractBuilder.BuilderProductB();        }    }    public class EntryPoint{        public static void Main(string[] args){            AbstractBuilder absBuilder = new ConcreteBuilder1();            Director.CreateBuilder(absBuilder);            Product p1 = absBuilder.GetResult();            p1.Show();            Console.Read();        }    }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.