SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 43 | Next

Hasin Hayder

"Object-Oriented Programming with PHP5"

So if you define that, all driver class must
have two methods named connect() and execute(). Now developers need not
worry while changing the driver, because they know that all these classes have
the same method definition. Interface helps in this scenario. Let's create the
interface here:
//interface.dbdriver.php
interface DBDriver
{
public function connect();
public function execute($sql);
}
?>
Chapter 2
[ 33 ]
Did you notice that the functions are empty in an interface? Now let's create our
MySQLDriver class, which implements this interface:
//class.mysqldriver.php
include("interface.dbdriver.php");
class MySQLDriver implements DBDriver
{ }
?>
Now if you execute the code above, it will give the following error because
MySQLDriver class has no connect() and execute() function as defined in the
interface. Let's run the code and read the error:
Fatal error: Class MySQLDriver contains 2 abstract methods
and must therefore be declared abstract or implement the remaining
methods (DBDriver::connect, DBDriver::execute) in C:\OOP with
PHP5\Codes\ch1\class.mysqldriver.php
on line 5

Well, now we have to add those two methods in our MySQLDriver class.


Pages:
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6