I need to write a script that will search through a CSV file, and perform certain search functions on it;
- find duplicate entries in a column
- find matches to a list of banned entries in another column
- find entries through regular expression matching on a column specified
Now, I have no problem at all coding this procedurally, but as I am now moving on to Object Orientated Programming, I would like to use classes and instances of objects instead.
However, thinking in OOP doesn't come naturally to me yet, so I'm not entirely sure which way to go. I'm not looking for specific code, but rather suggestions on how I could design the script.
My current thinking is this;
- Create a file class. This will handle import/export of data
- Create a search class. A child class of file. This will contain the various search methods
How it would function in index.php:
- get an array from the csv in the file object in index.php
- create a loop to iterate through the values of the array
- call the methods in the loop from a search object and echo them out
The problem I see with this approach is this;
- I will want to point at different elements in my array to look at particular "columns". I could just put my loop in a function and pass this as a parameter, but this kind of defeats the point of OOP, I feel
- My search methods will work in different ways. To search for duplicate entries is fairly straight forward with nested loops, but I do not need a nested loop to do a simple word or regular expression searchs.
Should I instead go like this?
- Create a file class. This will handle import/export of data
- Create a loop class A child of class of file. This will contain methods that deals with iterating through the array
- Create a search class. A child class of loop. This will contain the various search methods
My main issue with this is that it appears that I may need multiple search objects and iterate through this within my loop class.
Any help would be much appreciated. I'm very new to OOP, and while I understand the individual parts, I'm not yet able to see the bigger picture. I may be overcomplicating what it is I'm trying to do, or there may be a much simpler way that I can't see yet.