I'm trying to learn PHP OOP, but when I've followed tutorials, all the examples seem to involve things like:
class Human {
$_sex;
public function setSex($sex) {
$this->_sex = $sex;
}
public function getSex() {
return $this->sex;
}
}
(Pointless example, but hopefully you get what I mean -- An object has properties that are stored in the object.)
I've never come across a web application where I've needed to create objects about humans, dogs, cars, or any of the other weird examples you find when reading tutorials about OOP...
So I'm trying to find a similarly simple, but more realistic, project with which to learn OOP. I've chosen a website for an internet comic (e.g. XKCD.com). (This would allow people to view the comic, but also the author to edit and update it.)
So how would this translate to real-world PHP OOP?
My initial instinct would be to break the objects down thusly:
- Catalogue
- Episode
Where the Catalogue
class would contain methods pertaining to all the episodes of the comic, e.g. getMostRecentEpisodeID()
, deleteEpisode($episodeID)
, addNewEpisode($newEpisode)
, etc. etc.
And Episode
would contain methods pertaining to the individual episode, e.g. getEpisodeComments($episodeID)
(if the website allowed people to leave comments on individual episodes), editEpisode($episodeID)
, getEpisode($episodeID)
, etc.
Is this right, or have I made an absolute hash of what OOP is for?
Edit: Rather than just giving me a list of examples, it would really be helpful if your answer made specific reference to the problem I'm trying to solve.
Thanks.