mercredi 7 décembre 2016

OO Class Design - interacting two classes for searching

I'm trying to design my classes for a personal project but I'm stuck. I have much more experience in database design and can't find the OO solution to how my classes should best relate/interact.

My (PHP) project is a tool that will search for a given phrase throughout one or many pages of a single website. The output should show the phrase, how many times it was found, which pages it was found on, and how many times it occurred on that page.

So a phrase can have many related pages, and a page can contain many phrases.

I'm having a hard time grasping how to relate my two classes. I know that my phrase class will need to store the text phrase and the page class will need information about itself (page URL, page name, page content, etc).

Beyond that, I don't see where to logically store my methods that will need to

  • Search a page (or many pages) for a phrase
  • count how many times a phrase was found across all pages that were searched
  • count how many times a phrase occurred on each specific page
  • provide an excerpt of (for example) 20 characters surrounding each occurrence of the phrase from the page
  • return an array for the specific phrase containing the above information

Would it make sense to have a phraseFinder class that will take a phrase and one or more page(s), and have all these methods and information stored there?

Aucun commentaire:

Enregistrer un commentaire