RE: [PHP] Polymorphism question
| From: | Rick Emery | Date: | Fri, 15 Feb 2002 16:30:33 +0000 |
| Subject: | RE: [PHP] Polymorphism question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-84931@lists.php.net to get a copy of this message | ||
I've also done C and C++ since the 80's.
My experience with virtual, is that there is no base implementation for a
function. Rather, the function is expected to be defined in the derived
class.
The inheritance you describe would have a base implementation (no virtual
declaration), which could be over-ridden in the derived class.
Yes, PHP does have the latter capability.
-----Original Message-----
From: Richard Fox [mailto:rfox@sbsii.com]
Sent: Friday, February 15, 2002 9:01 AM
To: php-general@lists.php.net
Subject: [PHP] Polymorphism question
I am new to PHP but 10 years in C++
One of the cool/powerful things you can do in C++ is the following:
class DrawPlainDialog {
public:
...
virtual Draw(); // implementation draws a vanilla dialog box
};
class DrawStyleDialog : public DrawPlainDialog {
public:
...
virtual Draw(); // implementation draws better dialog
};
Somewhere in my code I have a function like:
void ShowGUI( DrawPlainDialog& dd ) {
dd.Draw();
}
ShowGUI can be called with any object that is derived from DrawPlainDialog,
obviously. Only code that calls ShowGUI must be changed when a new
implementation of DrawPlainDialog is used. This feature of C++ to have a
base class pointer (or reference) be able to access derived class
functionality is not something I've seen in any PHP documentation. Does it
exist, and if not is there a workaround for this highly desirable feature?
TIA
Rich
PS Can anyone point me to the most comprehensive OOP documentation for PHP?
----------
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php