GoConqr has a new look! Let us know what you think.

Notes

Interface_ex_1

Luis Rojas Spanish 1 page

Content of the notes (1)

Page 1

interface Logger {

public function execute($message);

}

class LogToFile implements Logger {

public function execute($message){

//code...

}

}

class LogToDb implements Logger {

public function execute($message){

//code...

}

}

class UsersController {

protected $logger;

// Over interface not implementation

public function __construct(Logger $logger){

$this->logger = $logger;

}

public function show(){

$user = 'Juan';

// The execute method will depend over which concrete class

$this->logger->execute($user);

}

}

$controller1 = new UsersController(new LogToFile);

$controller1->show();

$controller2 = new UsersController(new LogToDb);

$controller2->show();

Information

Description
Interface example
Created by
Luis Rojas
Views
97
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?