polymorphism در php

پولیمورفیسم روند ایجاد چندین آبجکت ها از یک کلاس است.
(polymorphism is the process of creating several objects from specific base classes.)
در واقع پولیمورفیسم بدین معنیه که شما از یک کلاس چندین ساب کلاس ایجاد میکنین.
برای بررسی اینکه کلاسی از کلاس دیگه ارث برده از instanceof استفاده میکنیم

$emailer = new Emailer("hasin@somewherein.net");
$extendedemailer = new ExtendedEmailer();
$htmlemailer = new HtmlEmailer("hasin@somewherein.net");
if ($extendedemailer instanceof emailer)
  echo "Extended Emailer is Derived from Emailer.";
if ($htmlemailer instanceof emailer)
  echo "HTML Emailer is also Derived from Emailer.";
if ($emailer instanceof htmlEmailer)
  echo "Emailer is Derived from HTMLEmailer.";
if ($htmlemailer instanceof extendedEmailer)
  echo "HTML Emailer is Derived from Emailer.";

خروجی :

Extended Emailer is Derived from Emailer.
HTML Emailer is also Derived from Emailer.

تدریس خصوصی برنامه نویسی PHP
۰۹۱۲۹۲۴۷۴۴۲

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *