Re: why interfaces ?

From: Date: Wed, 30 Apr 2008 18:06:41 +0000
Subject: Re: why interfaces ?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-37378@lists.php.net to get a copy of this message
Nathan Nobbe wrote:
all, in recent weeks there has been a lot of arguing about what interfaces are, arent (on php-general and now on the internals list as well) etc. etc. i am quite curious, why interfaces were added to the language in the first place. note, i am not criticizing them, i am overjoyed that the language has them, however i am curious about the history. is this something php borrowed from java? does it have anything to do with 'entirely virtual classes' in c++ ? i think that the history behind the addition of interfaces to php, would shed a lot of light on their intended purpose for use by php developers. thanks, -nathan
"Interfaces" exist in different OO-enabled languages. PHP strengthened its object model in PHP 5, and thus the introduction of interfaces. I'm pretty sure the intended purpose of interfaces was just like pretty much every other language. You implement interfaces in order to provide a consistent API. As long as class A implements interface B, I can be for certain that it's going to contain methods C and D. Interfaces also give you the ability to "type hint" against them, requiring objects that implement that interface, thus ensuring you know what methods are on that object. Interfaces are a very powerful feature, when implemented properly. -- Jeremy Privett C.E.O. & C.S.A. Omega Vortex Corporation http://www.omegavortex.net Please note: This message has been sent with information that could be confidential and meant only for the intended recipient. If you are not the intended recipient, please delete all copies and inform us of the error as soon as possible. Thank you for your cooperation.

« previous php.internals (#37378) next »