I'm reading some text files to create objects from. Which class should process the text files according to OOP principles?
I have my GUI object with a method to draw a table and fill it with data. This data is either parsed from an HTML page, or read from a cached text file. I can think of two ways to handle this, and I'd like to know which one is better.
Option 1:
public void drawSchedule()
{
try
{
if (CacheManager.hasData("schedule")) //this is not the complete logic, but enough for this post
{
String cacheString = CacheManager.readData(this, "schedule");
Schedule schedule = new Schedule(cacheString);
}
else
{
//read data from HTML page
}
catch (IOException e)
{
//generic error handling
e.printStackTrace();
}
}
Option 2:
public void drawSchedule()
{
try
{
if (CacheManager.hasData("schedule")) //this is not the complete logic, but enough for this post
{
String cacheString = CacheManager.readData(this, "schedule");
//parse data here so we end up with a bunch of variables
//courseList would be an ArrayList of Courses, if it makes any difference
Schedule schedule = new Schedule(firstDay, courseList);
}
else
{
//Read data from HTML page
}
catch (IOException e)
{
//generic error handling
e.printStackTrace();
}
}
parsingdone in Option 1?Schedulewould parse the string.