http://www.sitepoint.com/forums/showthread.php?t=342801

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi Jason,

you made the following claim on sitepoint (I would have reacted there
but couldn't be bother to crteate another website account) - which
I think is incorrect:

<QUOTE>
Nobody has yet brought up the slightly annoying issue that interfaces are actually implmented as abstract classes "under the hood". This means you can't decare two interfaces with an identical method name

PHP Code:
interface boat {
	public function drive();
	public function float();
}
interface car {
	public function drive();
	public function rotateTires();
}
class amphibious implements boat, car {
	public function float() {}
	public function drive() {}
	public function  rotateTires() {}
}
</QUOTE>

You are correct in that amphibious can't implement both car and boat but you
suggest that this is because of a problem with the engine and that it should be fixed.

But there is no problem and there is nothing to fix. (regardless of
interfaces a class can only implement a method once (we don't have C-like
function overloading) and that means you can't implement both interfaces,
besides which it makes no sense because if you we're allowed to implement
one drive() method to satisfy the 2 drive() interface methods then neither
the engine nor your code would know which of the 2 drive() methods
was actually bveing implemented (and if that cannot be determined then the
whole point of the interface becomes moot)

This misconception regarding broken interface functionality seems to seem from
content of your example. 'boat' and 'car' are not interfaces in my mind
 rather I would see them (and 'amphibious') as [abstract] classes and if
they were to implement an interface 'vehicle' springs to mind as a candidate.
(also boats aren't generally 'driven' ;-)

rgds,
Jochem

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux