I've been using the following problem to try out different ways of constructing
Java code. I get data from two sources, but in the same format, which is a directory of csv files. I want to see if the sources are producing the same results. So I need to compare data in the files. In one type of file, I use a key to find the right line and a column id to get the right data. In another, there is no key and I need to do a line by line comparison of a column, possible skipping a header, and there are other cases. I may want to run some or all cases, so I made an interface with the method compareData. That way any analysis methods don't need to worry about specifics. For each type of comparison I made an abstract class. My concrete classes provide the information about specific file names, key names and so on.
This exercise got me wondering about a few things.
1. I like the idea of using the same functions loadData() and testData() in all the implementations of the interface. But they are not coderanch. So rather than expose them, would it make sense to have an extra layer where I have another abstract class that defines these as abstract methods which is then extended for the individual types (see SECOND TRY below)?
2. In the methods loadData and testData, I just use the global variables I set when I create the concrete class. I don't pass an argument list. That allows me to have one abstract class that would be extended by all the
test classes (I just show one example). I don't even have a return value for load data for that reason (I might be loading numbers or arrays). Is that reasonable or sloppy?
3. I am a little worried about the parameters. I think I am set up well, if for example, the name of a key changes. I am willing to believe someday someone will decide to slip in another parameter and that would require changing a lot of code. I can create a class for the parameters, but it will be different for each basic type of test. I'm not seeing what that gets me in terms of maintainability. I had a look at generics, but didn't come up with any ideas. It seems that loadData() contains the bulk of the variability. I'm not quite seeing how to decouple it from the classes it will be in. Once I make MultivalueTest and ListTest, etc., each will implement their own loadData() because what they look for and what they load are different.
Any comments about my concerns or suggestions for the code are welcome. Thanks in advance.
FIRST TRY
and these bits so it all works
SECOND TRY