コード例 #1
0
        private static void Main(string[] args)
        {
            FileDecorator file = new FileDecorator(new LocationDecorator(new VideoDecorator(
                                                                             new MobilePhone("869453109", "Galaxy S8"),
                                                                             "Video", "0101010100010001010100001010"), "Location", 24.23, 12.54), "File", "project", "docx");
            FileDecorator smartphone = new FileDecorator(new LocationDecorator(new VideoDecorator(
                                                                                   new SmartPhone("869453122", "Galaxy S8", "Android"),
                                                                                   "Video", "0101010100010001010100001010"), "Location", 24.23, 12.54), "File", "project", "docx");

            // file.TextMessage("869287198", "Labas");
            //smartphone.Call("867546189");
            Console.WriteLine(Environment.NewLine);
            // Phone phon = PhoneDecorator.GetRole(file, "Video");
            // ((VideoDecorator)phon).TextMessage("861199", "Sveiki!");
            Phone ph = PhoneDecorator.RemoveRole(file, "Location");

            ((FileDecorator)ph).Call("865839182");
            Console.ReadKey();
        }
コード例 #2
0
        public static Phone RemoveRole(Phone phone, string role)
        {
            Phone temp = phone;

            if (((PhoneDecorator)phone).GetRoleName().Equals(role))
            {
                return(((PhoneDecorator)temp).Phone);
            }
            else if (((PhoneDecorator)phone).Phone is PhoneDecorator &&
                     ((PhoneDecorator)((PhoneDecorator)phone).Phone).GetRoleName().Equals(role))
            {
                ((PhoneDecorator)temp).Phone = ((PhoneDecorator)((PhoneDecorator)phone).Phone).Phone;
                return(temp);
            }
            else
            {
                PhoneDecorator.RemoveRole(((PhoneDecorator)phone).Phone, role);
            }
            return(temp);
        }