Abstract Class
Soyutlama, sadece girdi ve çıktıya bakıp içeride dönen işlemlerin gizlenmesi olarak açıklanabilir.
abstract class tan object üretilmez.
    class Shape {
        public int Width { get; set; }
        public int Height { get; set; }
        public Shape(int w, int h)
        {
            this.Width = w;
            this.Height = h;
        }
        public int AlanHesapla(){
            return this.Width * this.Height;
        }
        public virtual void Draw () {
            Console.WriteLine("Şekil çiz");
        }
    }
    class Square:Shape {
        public Square(int w, int h):base(w,h)
        {
            
        }
        public override void Draw () {
            Console.WriteLine("Kare çiz");
        }
    }
    class Rectangle:Shape {
        public Rectangle(int w, int h):base(w,h)
        {
            
        }
        public override void Draw () {
            Console.WriteLine("Dikdörtgen çiz");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var shapes = new Shape[3];
            
            shapes[0] = new Square(15,15);
            shapes[1] = new Rectangle(20,25);
            shapes[2] = new Rectangle(3,5);
            foreach (var shape in shapes){
                shape.Draw();
                Console.WriteLine($"Alan: {shape.AlanHesapla()}");
            }
        }
    }
    
/*
Çıktısı
Kare çiz
Alan: 225
Dikdörtgen çiz
Alan: 500
Dikdörtgen çiz
Alan: 15
*/
Last updated
Was this helpful?
