Re: Why i believe we need final
| From: | Stanislav Malyshev | Date: | Mon, 27 Jan 2003 14:52:00 +0000 |
| Subject: | Re: Why i believe we need final | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-93709@lists.php.net to get a copy of this message | ||
MB>> Consider you defined a container (list, vector what ever) and want
MB>> to derive from it. Then there is *really*no* need to override methods
MB>> like "insert" or "remove". You may want to have additional things
MB>> like
MB>> "insert_if" or whatever. But for the container part "insert" must
MB>> stay as
MB>> it is and that requires static binding.
Well, if there is *really no need*, why one would override it? Obviously,
if one overrides it, there's a need? I don't see why container writer
should care if anyone overrides the method. Could you bring a real example
where one needs non-overridable methods? Only thing I can think of are
various Java security classes (like class loaders, etc.) which if you
succeed to override various checking hooks may lead to trouble. But we
don't have such things in PHP...
For example, what if I want to create "secure container", where insert can
be done only after you called password() function for the container with
right password? Your 'finalized' container would not allow me to do it.
MB>> And here comes "final" as it allows to emulate static binding with
MB>> dynamic binding. If you declare a function "final" it is invariant
MB>> against inhertance starting from that point in the inhertance tree. In
Could you explain what is "invariant against inhertance"? What should
happen if I define function with the same name in derived class - is this
a compile error?
--
Stanislav Malyshev, Zend Products Engineer
stas@zend.com http://www.zend.com/ +972-3-6139665 ext.109