note 107849 added to language.oop5.interfaces
| From: | guillaume at metayer dot ca | Date: | Fri, 09 Mar 2012 15:11:19 +0000 |
| Subject: | note 107849 added to language.oop5.interfaces | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186564@lists.php.net to get a copy of this message | ||
I think good OOP design will actually require both what dlovell2001 and anon said. In the examples
below, if Database is only an abstract class, you will have limitations. What if one day you have a
special Database object that is so different for some specific needs, that it should NOT inherit
from the Database abstract class? You would be stuck. In my opinion, the best thing to do would be
to have a Database abstract class that implements a DatabaseInterface interface.
When working on a Database object, you would first make sure it implements the DatabaseInterface
object (dlovell2001, this is something very important that's missing in your example). You can
still use any object inheriting the Database class (because this class implements the
DatabaseInterface interface) but you are NOT limited to using an object inheriting from Database.
Any object implementing the DatabaseInterface will do. This way, you are not limited to a specific
type.
Interfaces are a good way to have a 'contract' with the component using a certain object,
without being limited to using a specific type for that object. Also remember to use the
'instanceof' or similar when working on such object. One goal of interfaces is to actually
enforce the signature of an object before actually working with it.
----
Server IP: 69.147.83.197
Probable Submitter: 69.70.27.42
----
Manual Page -- http://www.php.net/manual/en/language.oop5.interfaces.php
Edit -- https://master.php.net/note/edit/107849
Del: integrated -- https://master.php.net/note/delete/107849/integrated
Del: useless -- https://master.php.net/note/delete/107849/useless
Del: bad code -- https://master.php.net/note/delete/107849/bad+code
Del: spam -- https://master.php.net/note/delete/107849/spam
Del: non-english -- https://master.php.net/note/delete/107849/non-english
Del: in docs -- https://master.php.net/note/delete/107849/in+docs
Del: other reasons-- https://master.php.net/note/delete/107849
Reject -- https://master.php.net/note/reject/107849
Search -- https://master.php.net/manage/user-notes.php