Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
 public void Play(AbstractPhone phone)
 {
     Console.WriteLine("AbstractPhone Play - {0} Update", phone);
     phone.System();
     phone.Call();
 }
Ejemplo n.º 3
0
 public void PlayAbstract(AbstractPhone phone)
 {
     Console.WriteLine($"Use{phone.GetType().Name}");
     phone.Call();
     phone.SendMessage();
 }
Ejemplo n.º 4
0
        ///// <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();
        }