예제 #1
0
        public object Clone()
        {
            //---if this class contain reference types---
            //---i must do this----
            WoodenDoor w = new WoodenDoor();

            w.material = this.material;
            w.Price    = this.Price;
            return(w);
        }
예제 #2
0
        static void Main(string[] args)
        {
            // IDoor d = new IDoor(); - cant create object of interface
            WoodenDoor d  = new WoodenDoor();
            MetalDoor  d1 = new MetalDoor();

            d.ShowPicture();

            IDoor[] doors = new IDoor[4]
            {
                new WoodenDoor(),
                new MetalDoor(),
                new MetalDoor(),
                new WoodenDoor()
            };

            foreach (var item in doors)
            {
                item.ShowInfo();
            }

            ShowAboutDoor(d);
            ShowAboutDoor(d1);

            //---lost object---
            d = null;
            //----ELVIS OPERATOR---
            d = d ?? new WoodenDoor();
            d.ShowInfo();

            //---int nullable---

            //  int[] arr = null;// - can do this
            //  arr[0] = null;//---cant't do this, no nullable type int
            Show1(null, 5, null);
            Show2(null);

            //----OPENABLE DOOR---
            Header("OPENABLE DOOR");
            d1.Open();
            d1.ShowInfo();
            d1.Close();
            d1.ShowInfo();

            //OpenClose((IOpenable)d);
            OpenClose(d1);
            d1.ShowInfo();


            Header("ICLONABLE");
            WoodenDoor w5 = (WoodenDoor)d.Clone();

            w5.ShowInfo();

            IDoor newClone = (IDoor)ShowClone((IClonable)doors[1]);

            newClone.ShowInfo();

            Window w    = new Window("my very expencive window");
            Window newW = (Window)ShowClone((IClonable)w);

            newW.Show();
        }