note 114038 added to language.oop5.final
| From: | someonedotelseatelsewheredotnet | Date: | Sat, 04 Jan 2014 22:40:56 +0000 |
| Subject: | note 114038 added to language.oop5.final | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198107@lists.php.net to get a copy of this message | ||
@thomas at somewhere dot com
The 'final' keyword is extremely useful. Inheritance is also useful, but can be abused
and becomes problematic in large applications. If you ever come across a finalized class or method
that you wish to extend, write a decorator instead.
<?php
final class Foo
{
public method doFoo()
{
// do something useful and return a result
}
}
final class FooDecorator
{
private $foo;
public function __construct(Foo $foo)
{
$this->foo = $foo;
}
public function doFoo()
{
$result = $this->foo->doFoo();
// ... customize result ...
return $result;
}
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/language.oop5.final.php
Edit -- https://master.php.net/note/edit/114038
Del: integrated -- https://master.php.net/note/delete/114038/integrated
Del: useless -- https://master.php.net/note/delete/114038/useless
Del: bad code -- https://master.php.net/note/delete/114038/bad+code
Del: spam -- https://master.php.net/note/delete/114038/spam
Del: non-english -- https://master.php.net/note/delete/114038/non-english
Del: in docs -- https://master.php.net/note/delete/114038/in+docs
Del: other reasons-- https://master.php.net/note/delete/114038
Reject -- https://master.php.net/note/reject/114038
Search -- https://master.php.net/manage/user-notes.php