mardi 19 septembre 2017

php structuring classes properly to provide the required functionalities

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;
    }
}

Please help to implement these functionalities by using a proper pattern:

  1. Each Author should represent a list of articles (ArticleList) may be something like this?

    class ArticleList {
        private $articles = [];
        public function addArticle(Article $article) {
            $this->articles[] = $article;
        }
    }
    
    
  2. Change the Author of an Article

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire