কম্পিউটার টিউটোরিয়াল

C#-এ ডাইনামিক পলিমরফিজম (Dynamic Polymorphism) কী?

পলিমরফিজম বা বহুরূপতা দুটি প্রকারের: স্ট্যাটিক এবং ডাইনামিক। স্ট্যাটিক পলিমরফিজমে, একটি ফাংশনের প্রতিক্রিয়া কম্পাইল টাইমে নির্ধারিত হয়। ডাইনামিক পলিমরফিজমে, এটি রান-টাইমে সিদ্ধান্ত নেওয়া হয়।

ডাইনামিক পলিমরফিজম abstract classes এবং virtual functions দ্বারা ইমপ্লিমেন্ট করা হয়। নিচে ডাইনামিক পলিমরফিজমের একটি উদাহরণ দেওয়া হলো:

উদাহরণ

using System; 
namespace PolymorphismApplication { 
    class Shape { 
        protected int width, height; 
        public Shape(int a = 0, int b = 0) { 
            width = a; 
            height = b; 
        } 
        public virtual int area() { 
            Console.WriteLine("Parent class area :"); 
            return 0; 
        } 
    } 
    class Rectangle : Shape { 
        public Rectangle(int a = 0, int b = 0) : base(a, b) { } 
        public override int area() { 
            Console.WriteLine("Rectangle class area :"); 
            return (width * height); 
        } 
    } 
    class Triangle : Shape { 
        public Triangle(int a = 0, int b = 0) : base(a, b) { } 
        public override int area() { 
            Console.WriteLine("Triangle class area :"); 
            return (width * height / 2); 
        } 
    } 
    class Caller { 
        public void CallArea(Shape sh) { 
            int a; 
            a = sh.area(); 
            Console.WriteLine("Area: {0}", a); 
        } 
    } 
    class Tester { 
        static void Main(string[] args) { 
            Caller c = new Caller(); 
            Rectangle r = new Rectangle(10, 7); 
            Triangle t = new Triangle(10, 5); 
            c.CallArea(r); 
            c.CallArea(t); 
            Console.ReadKey(); 
        } 
    } 
}

আউটপুট

Rectangle class area : Area: 70 Triangle class area : Area: 25
  1. আইপি ঠিকানা কী?

  2. ডাইনামিক DNS (DDNS) কী?

  3. ডাইনামিক আইপি অ্যাড্রেস কী?

  4. Windows 10-এ Dynamic Updates কী?