1

I'm a relative newbie to OOP, and I am getting this error on a learning exercise.

Class contains 6 abstract methods and must therefore be declared abstract or implement the remaining methods

the error is being thrown from a child class of an abstract class, implementing an interface. I understand that children of an abstract class must implement all abstract methods, but I am not declaring any abstract methods in the parent class or the interface. Shouldn't I only be getting this error if I am not including, in the child class, a declared abstract method from the abstract class or interface?

child class:

class OuterViewDecorator extends AbstractViewDecorator
    {
    const DEFAULT_TEMPLATE = "/var/www/portfolio/simple-php/templates/layout.php";

    public function render() {
        $data["innerview"] = $this->view->render();
        return $this->renderTemplate($data);
    }
}

parent class:

abstract class AbstractViewDecorator implements ViewInterface
{
    const DEFAULT_TEMPLATE = "default.php";
    protected $template = self::DEFAULT_TEMPLATE;
    protected $view;    

    public function __construct(ViewInterface $view)
    {
        $this->view = $view;
    }   

    public function render()
    {
        return $this->view->render();
    }   

    public function renderTemplate(array $data = array())
    {
        extract($data);
        ob_start();
        $template = include $this->template;
        return ob_get_clean($template);
    }
}

interface:

interface ViewInterface
{
    public function setTemplate($template);
    public function getTemplate();
    public function __set($field, $value);
    public function __get($field);
    public function __isset($field);
    public function __unset($field);
    public function render();
}

thanks for any help

4

1 回答 1

2

You are saying it is implementing an interface.

Between all of the inheriting classes must implement all of the interface methods So for example your AbstractViewDecorator could implement 2 of the methods, and OuterViewDecorator could implement the last 4, or OuterViewDecorator could do all 6.. As long as all of the methods are implements in the class inheritance chain.

于 2013-07-03T20:28:36.890 回答