Ejemplo n.º 1
0
        /// <summary>
        /// Static Main method
        /// </summary>
        /// <param name="args">programs arguments list</param>
        static void Main(string[] args)
        {
            var items = new List <FurnitureItem>()
            {
                new FurnitureItem("Sectional Couch", 55.5, 22.4, 78.6, 35.0),
                new FurnitureItem("Nightstand", 25.0, 12.4, 20.0, 10.0),
                new FurnitureItem("Dining Table", 105.0, 35.4, 100.6, 55.5),
            };

            // create report Builder and it's Director class [Here how to apply Builder design pattern using Director class]
            DailyReportBuilder     inventoryReportBuilder = new DailyReportBuilder(items);
            InventoryBuildDirector director = new InventoryBuildDirector(inventoryReportBuilder);

            // call build report using director then getting it
            director.BuildCompleteReport();
            InventoryReport inventoryReport = inventoryReportBuilder.GetDailyReport();

            Console.WriteLine(inventoryReport.Debug());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var furnitureItems = new List <FurnitureItem>
            {
                new FurnitureItem("Sectional Couch", 55.5, 22.4, 78.6, 35.0),
                new FurnitureItem("Nightstand", 25.0, 12.4, 20.0, 10.0),
                new FurnitureItem("Dining Table", 105.0, 35.4, 100.6, 55.5),
            };

            #region Builder Example

            // Builder Example with Director

            var inventorybuilder = new DailyReportBuilder(furnitureItems);
            var director         = new InventoryBuildDirector(inventorybuilder);

            director.BuildCompleteReport();
            var directoryReport = inventorybuilder.GetDailyReport();

            Console.WriteLine(directoryReport.Debug());

            #endregion

            #region Fluent Builder Example

            // We can implement Inventory Builder as Fluent Builder (without director) like below
            // With this approach we can select building features.

            var inventoryFluentBuilder = new DailyReportFluentBuilder(furnitureItems);

            var fluentReport = inventoryFluentBuilder
                               .AddTitle()
                               .AddDimensions()
                               .AddLogistics(DateTime.Now)
                               .GetDailyReport();

            Console.WriteLine(fluentReport.Debug());

            #endregion
        }