I have following classes:
class Author {
public $id;
public $name;
}
class Article {
protected $author; // Author
protected $title; // String
public function __construct(Author $author, string $title)
$this->author = $author;
$this->title = $title;
}
}
The requirement is to implement these functionalities
- Each
Author
represents a list of articles - Changing the
Author
of anArticle
I first thought of having a class:
class ArticleList {
public $author; // Author
private $articles = [];
public function addArticle(Article $article) {
$this->articles[] = $article;
}
}
But this seems to be wrong, isn't?, because each Article
already have Author
, a bit confusing to me, help is appreciated.
Thanks in advance!