【发布时间】:2017-09-19 10:25:01
【问题描述】:
我有以下课程:
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;
}
}
要求是实现这些功能
- 每个
Author代表一个文章列表 - 更改
Author的Article
我首先想到要上课:
class ArticleList {
public $author; // Author
private $articles = [];
public function addArticle(Article $article) {
$this->articles[] = $article;
}
}
但这似乎是错误的,不是吗?因为每个Article 已经有Author,我有点困惑,感谢帮助。
提前致谢!
【问题讨论】:
标签: php design-patterns