仓储抽象类演示

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("你要什么电脑?");
            string strs = Console.ReadLine();
             Brand _bran =  Faloy.GetBranName(strs);
             _bran.ShowBrand();

        }



    }


    public abstract class Brand
    {
        public abstract void ShowBrand();
    }

    public class Dell : Brand
    {

        public override void ShowBrand()
        {
            Console.WriteLine("Dell");
        }
    }
    public class HP : Brand
    {
        public override void ShowBrand()
        {
            Console.WriteLine("HP");
        }
    }


    public static class Faloy
    {
        public static Brand GetBranName(string str)
        {
            if (str == "dell")
                return new Dell();
            else if (str == "hp") return new HP();
            return null;
        }
    }
}
View Code

 

posted @ 2015-06-04 22:02  kevin.dai  阅读(197)  评论(0编辑  收藏  举报