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!");
            }
        }
    }
  • 相关阅读:
    RSA使用
    C#获取主机信息
    NSIS打包软件使用
    C#获取局域网主机
    C#实现Web链接启动应用程序
    4.布局介绍
    Server Sql 多表查询、子查询和分页
    C# File类常用方法
    Vue 使用技巧手记
    前端面试题手记
  • 原文地址:https://www.cnblogs.com/youguess/p/8662170.html
Copyright © 2011-2022 走看看