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();
        }
        ///// <summary>
        ///// 依赖细节,导致底层的变化传递到上层
        ///// </summary>
        ///// <param name="phone"></param>

        //public void PlayPhone(Iphone phone)
        //{
        //    Console.WriteLine($" {nameof(phone)}");
        //    phone.Call();
        //    phone.Text();
        //}
        //public void PlayLumia(Lumia phone)
        //{
        //    Console.WriteLine($" {nameof(phone)}");
        //    phone.Call();
        //    phone.Text();
        //}


        // 更具扩展性,
        public void Play(AbstractPhone phone)
        {
            Console.WriteLine($" {nameof(phone)}");
            phone.Call();
            phone.Text();
        }