zoukankan      html  css  js  c++  java
  • C#面向对象17 23种设计模式

    1.简单工厂模式

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 简单工厂
    {
        class Program
        {
            static void Main(string[] args)
            {
                string tt= Console.ReadLine();
                Notabook tb = Getbook(tt);
                tb.Say();
                Console.ReadKey();
            }
    
            /// <summary>
            /// 简单工厂核心,根据输入 创建对象赋值给父类~
            /// </summary>
            /// <param name="style"></param>
            /// <returns></returns>
            public static Notabook Getbook(string style)
            {
                Notabook tb = null;
                switch(style)
                {
                    case "lenvon":
                        tb=new lenvon();
                        break;
                    case "IBM":
                        tb = new IBM();
                        break;
                    case "DELL":
                        tb = new DELL();
                        break;
                }
                return tb;
            }
        }
    
        public abstract class Notabook
        {
            public abstract void Say();
        }
    
        public class lenvon: Notabook
        {
            public override void Say()
            {
                Console.WriteLine("this is lenvon!");
            }
        }
    
        public class IBM:Notabook
        {
            public override void Say()
            {
                Console.WriteLine("this is IBM!");
            }
        }
    
        public class DELL:Notabook
        {
            public override void Say()
            {
                Console.WriteLine("this is DELL!");
            }
        }
    }
  • 相关阅读:
    jsonp 的 post
    js replace常用用法
    zindex
    x秒前
    手写jsonp
    webview 冒泡慢?
    人民币大写转阿拉伯数字
    checked
    Deadlock Troubleshooting Trace 1222
    [转]基于LUCENE实现自己的推荐引擎
  • 原文地址:https://www.cnblogs.com/youguess/p/8662170.html
Copyright © 2011-2022 走看看