Beispiel #1
0
        static void Main(string[] args)
        {
            var         output  = new OutputConsole();
            MobilePhone myPhone = new MobilePhone(output);

            Console.WriteLine(myPhone.GetFullDescription());
            Run(ref myPhone);
        }
Beispiel #2
0
        public static void Attach(ref MobilePhone myPhone)
        {
            Console.WriteLine("Select component to attach(specify index)");
            List <string> soundComponent = new List <string>()
            {
                "iPhoneHeadset", "PhoneSpeaker", "LoudSpeaker", "SamsungHeadset", "UnofficialPhoneHeadset"
            };

            for (int i = 0; i < soundComponent.Count; i++)
            {
                Console.WriteLine($"{i + 1}: Attach {soundComponent[i]}");
            }

            var chooseAttachType = int.Parse((Console.ReadKey().KeyChar.ToString()));

            Console.WriteLine("\n");

            PlaySound device;
            var       output1 = new OutputConsole();

            switch (chooseAttachType)
            {
            case 1:
                device = new iPhoneHeadset(output1);
                break;

            case 2:
                device = new PhoneSpeaker(output1);
                break;

            case 3:
                device = new LoudSpeaker(output1);
                break;

            case 4:
                device = new SamsungHeadset(output1);
                break;

            case 5:
                device = new UnofficialPhoneHeadset(output1);
                break;

            default:
                device = new PhoneSpeaker(output1);
                break;
            }

            myPhone.AttachDevice(ref device);
        }