Exemple #1
0
        /// <summary>
        /// 依赖细节--只能是iPhone或者其他子类
        /// 不同的手机需要多个方法
        /// 有没有办法,一个方法满足不同类型手机的需求?
        /// </summary>
        /// <param name="phone"></param>
        //public void PlayPhone(iPhone phone)
        //{
        //    Console.WriteLine("Use {0}", phone.GetType().Name);
        //    phone.Call();
        //    phone.Text();
        //}
        //public void PlayPhone(HTC phone)
        //{
        //    Console.WriteLine("Use {0}", phone.GetType().Name);
        //    phone.Call();
        //    phone.Text();
        //}

        /// <summary>
        /// 依赖抽象--只要是AbstractPhone极其子类都可以
        /// </summary>
        /// <param name="phone"></param>
        public void PlayPhone(AbstractPhone phone)
        {
            Console.WriteLine("Use {0}", phone.GetType().Name);
            phone.Call();
            phone.Text();
        }
Exemple #2
0
 public void PlayAbstract(AbstractPhone phone)
 {
     Console.WriteLine($"Use{phone.GetType().Name}");
     phone.Call();
     phone.SendMessage();
 }