note 82111 added to language.oop5.abstract
| From: | ironiridis at gmail dot com | Date: | Thu, 27 Mar 2008 21:56:30 +0000 |
| Subject: | note 82111 added to language.oop5.abstract | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137645@lists.php.net to get a copy of this message | ||
Just one more time, in the simplest terms possible:
An Interface is like a protocol. It doesn't designate the behavior of the object; it designates
how your code tells that object to act. An interface would be like the English Language: defining an
interface defines how your code communicates with any object implementing that interface.
An interface is always an agreement or a promise. When a class says "I implement interface
Y", it is saying "I promise to have the same public methods that any object with interface
Y has".
On the other hand, an Abstract Class is like a partially built class. It is much like a document
with blanks to fill in. It might be using English, but that isn't as important as the fact that
some of the document is already written.
An abstract class is the foundation for another object. When a class says "I extend abstract
class Y", it is saying "I use some methods or properties already defined in this other
class named Y".
So, consider the following PHP:
<?php
class X implements Y { } // this is saying that "X" agrees to speak language "Y"
with your code.
class X extends Y { } // this is saying that "X" is going to complete the partial class
"Y".
?>
You would have your class implement a particular interface if you were distributing a class to be
used by other people. The interface is an agreement to have a specific set of public methods for
your class.
You would have your class extend an abstract class if you (or someone else) wrote a class that
already had some methods written that you want to use in your new class.
These concepts, while easy to confuse, are specifically different and distinct. For all intents and
purposes, if you're the only user of any of your classes, you don't need to implement
interfaces.
----
Server IP: 69.147.83.197
Probable Submitter: 70.91.178.185
----
Manual Page -- http://www.php.net/manual/en/language.oop5.abstract.php
Edit -- https://master.php.net/note/edit/82111
Del: integrated -- https://master.php.net/note/delete/82111/integrated
Del: useless -- https://master.php.net/note/delete/82111/useless
Del: bad code -- https://master.php.net/note/delete/82111/bad+code
Del: spam -- https://master.php.net/note/delete/82111/spam
Del: non-english -- https://master.php.net/note/delete/82111/non-english
Del: in docs -- https://master.php.net/note/delete/82111/in+docs
Del: other reasons-- https://master.php.net/note/delete/82111
Reject -- https://master.php.net/note/reject/82111
Search -- https://master.php.net/manage/user-notes.php