بيت » تعدد الأشكال (البرمجة)

تعدد الأشكال (البرمجة)

1967
  • Christopher Strachey
Computer programming workspace demonstrating polymorphism with code snippets.

Polymorphism, from Greek for “many shapes,” allows objects of different classes to be treated as objects of a common superclass. It enables a single interface, such as a method name, to be used for a general class of actions. The specific action is determined by the exact type of the object at runtime. This is often achieved through method overriding.

Polymorphism is a powerful concept that allows for writing flexible and decoupled code. The most common form in OOP is subtype polymorphism, which is enabled by inheritance and الطريقة overriding. When a subclass provides a specific implementation for a method that is already defined in its superclass, it is called overriding. A variable of the superclass type can refer to an object of any of its subclasses. When a method is called on this variable, the version of the method that gets executed is the one belonging to the object’s actual class, not the variable’s type. This decision is made at runtime, a process known as dynamic dispatch or late binding.

For example, consider a superclass ‘Shape’ with a method ‘calculateArea()’. Subclasses like ‘Circle’ and ‘Rectangle’ can inherit from ‘Shape’ and provide their own specific implementations of ‘calculateArea()’. A program can then have a list of ‘Shape’ objects, containing both ‘Circle’ and ‘Rectangle’ instances. When iterating through the list and calling ‘calculateArea()’ on each element, the correct formula will be used for each shape automatically. This eliminates the need for long ‘if-else’ or ‘switch’ statements to check the type of each object, leading to cleaner, more extensible code. New shapes can be added to the system without modifying the code that processes them.

UNESCO Nomenclature: 1203
- علوم الحاسب الآلي

النوع

النظام التجريدي

الاضطراب

تزايدي

الاستخدام

الاستخدام الواسع النطاق

السلائف

  • مفهوم مؤشرات الوظيفة في لغات مثل c
  • مفاهيم البرمجة العامة
  • الميراث، الذي يوفر التسلسل الهرمي للفئة اللازم لتعدد أشكال النوع الفرعي
  • the need for flexible and extensible برمجة الأنظمة

التطبيقات

  • drawing different shapes (‘circle’, ‘square’) using a single ‘draw()’ method call
  • processing various document types (‘pdf’, ‘word’) with a generic ‘print()’ function
  • implementing واجهة المستخدم event handlers
  • المجموعات العامة التي يمكنها أن تحتوي على كائنات من أنواع مختلفة ولكنها ذات صلة
  • أطر حقن التبعيات

براءات الاختراع:

NA

أفكار ابتكارات محتملة

!!مستويات !!! العضوية مطلوبة

يجب أن تكون عضوًا !!! مستويات!!! للوصول إلى هذا المحتوى.

انضم الآن

هل أنت عضو بالفعل؟ سجّل الدخول هنا
Related to: polymorphism, overriding, dynamic dispatch, late binding, subtype, interface, abstraction, oop, method overriding, runtime.

اترك تعليقاً

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *

متاح للتحديات الجديدة
مهندس ميكانيكي، مشروع، هندسة العمليات أو مدير البحث والتطوير
تطوير المنتج الفعال

متاح لتحدي جديد في غضون مهلة قصيرة.
تواصل معي على LinkedIn
تكامل الإلكترونيات المعدنية والبلاستيكية، التصميم مقابل التكلفة، ممارسات التصنيع الجيدة (GMP)، بيئة العمل، الأجهزة والمواد الاستهلاكية متوسطة إلى عالية الحجم، التصنيع المرن، الصناعات الخاضعة للتنظيم، شهادات CE وFDA، التصميم بمساعدة الحاسوب (CAD)، Solidworks، الحزام الأسود من Lean Sigma، شهادة ISO 13485 الطبية

نحن نبحث عن راعي جديد

 

هل شركتك أو مؤسستك متخصصة في التقنية أو العلوم أو الأبحاث؟
> أرسل لنا رسالة <

احصل على جميع المقالات الجديدة
مجاني، لا يوجد بريد عشوائي، ولا يتم توزيع البريد الإلكتروني ولا إعادة بيعه

أو يمكنك الحصول على عضويتك الكاملة -مجانًا- للوصول إلى جميع المحتويات المحظورة >هنا<

السياق التاريخي

(إذا كان التاريخ غير معروف أو غير ذي صلة، على سبيل المثال "ميكانيكا الموائع"، يتم تقديم تقدير تقريبي لظهوره الملحوظ)

الاختراع والابتكار والمبادئ التقنية ذات الصلة

انتقل إلى الأعلى

قد يعجبك أيضاً