zoukankan      html  css  js  c++  java
  • Design Pattern

        class BridgePattern
        {
            public static void Main()
            {
                IReport reportMonthly = new MonthlyReport();
                IReport reportYearly = new YearlyReport();
    
                ReportChart reportChart = new ColumnReportChart();
    
                reportChart.SetReport(reportMonthly);
                reportChart.Display();
    
                reportChart.SetReport(reportYearly);
                reportChart.Display();
            }
        }
    
        abstract class ReportChart
        {
            protected IReport report;
    
            public void SetReport(IReport rpt)
            {
                report = rpt;
            }
    
            public abstract void Display();
        }
    
        class ColumnReportChart : ReportChart
        {
            public override void Display()
            {
                Console.WriteLine("------------{0} by 'Column Chart!!'-------------", report.ReportName);
                foreach (var item in report.GetReportData())
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine();
            }
        }
    
        class PieReportChart : ReportChart
        {
            public override void Display()
            {
                Console.WriteLine("------------{0} by 'Pie Chart!!'-------------", report.ReportName);
                foreach (var item in report.GetReportData())
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine();
            }
        }
    
        interface IReport
        {
            string ReportName { get; }
            List<string> GetReportData();
        }
    
        class YearlyReport : IReport
        {
            public List<string> GetReportData()
            {
                var data = new List<string> 
                {
                  "2010,370",
                  "2011,420",
                  "2012,320",
                  "2013,490",
                };
                return data;
            }
    
            public string ReportName
            {
                get { return "Yearly Report"; }
            }
        }
    
        class MonthlyReport : IReport
        {
            public List<string> GetReportData()
            {
                var data = new List<string> 
                {
                  "Jan,370",
                  "Feb,420",
                  "Mar,320",
                  "Apr,490"
                };
                return data;
            }
    
            public string ReportName
            {
                get { return "Monthly Report"; }
            }
        }
  • 相关阅读:
    HTTP深入浅出 http请求
    ASP.NET MVC 4
    ASP.NET MVC 4 (十三) 基于表单的身份验证
    ASP.NET MVC 4 (十二) Web API
    ASP.NET MVC 4 (十一) Bundles和显示模式
    ASP.NET MVC 4 (十) 模型验证
    ASP.NET MVC 4 (九) 模型绑定
    ASP.NET MVC 4 (八) URL链接和Ajax帮助函数
    ASP.NET MVC 4 (七) 模板帮助函数
    ASP.NET MVC 4 (六) 帮助函数
  • 原文地址:https://www.cnblogs.com/cnbwang/p/3660457.html
Copyright © 2011-2022 走看看