示例#1
0
        static void Main(string[] args)
        {
            #region 简单工厂
            MaYun man1 = SimpleFactory.CreateMaYun("Man");
            man1.Money();
            man1.Company();
            MaYun woman1 = SimpleFactory.CreateMaYun("Woman");
            woman1.Money();
            woman1.Company();
            #endregion

            #region 工厂
            IFactory factory = new ManFactory();
            MaYun    mm      = factory.CreateMaYun();
            mm.Company();
            mm.Money();
            #endregion
        }
示例#2
0
        public static MaYun CreateMaYun(string type)
        {
            MaYun m = null;

            switch (type)
            {
            case "Man":
                m = new Man();
                break;

            case "Woman":
                m = new Woman();
                break;

            default:
                break;
            }
            return(m);
        }