PHP Designing Interfaces in PHP Using Interfaces Implementing Interfaces

Implementing interfaces

I didnt understant this question can some please help me with its codeing

Write a class named "Treehouse" that sets and retrieves the correct details by uses the following Interface: interface Learnable { public function setTitle($title); public function setContentType($type = 'video'); public function setLocation($loc);

public function getTitle();
public function getContentType();
public function getLocation();

}

Treehouse.php
<?php
class Treehouse implements Iterator,countable
{
    public function setTitle($title);
    public function setContentType($type = 'video');
    public function setLocation($loc);

    public function getTitle();
    public function getContentType();
    public function getLocation();
}

1 Answer

Daniel Marin
Daniel Marin
8,018 Points

Hi Dipika Purohit You need to implement Learnable which means the class Tree needs to abide to the Learnable contract Here's how you can do it:

<?php

class Treehouse implements Learnable {

  private $title;
  private $type;
  private $loc;

  public function setTitle($title) {
    $this->title = $title;
  }

  public function setContentType($type = 'video') {
    $this->type = $type;
  }

  public function setLocation($loc) {
    $this->loc = $loc;
  }

  public function getTitle() {
    return $this->title;
  }

  public function getContentType() {
    return $this->type;
  }

  public function getLocation() {
    return $this->loc;
  }

}

thanx Daniel Marin