Making things private (as opposed to protected) in an object language is extremely anti-social, because it prevents people from inheriting and expanding the class. For example, I wrote the below code to try and overcome issue #48 (i.e. stop getProperty() from throwing an exception), but it failed to compile because the members of CsvIterator are private. Don't do that. Make all data members protected.
CsvParser p = new CsvParser() {
// all this code is so we can have a csv line that doesn't throw
// an exception if some columns are missing.
Iterator parse(Map args = [:], Reader reader) {
def csvReader = createCSVReader(args, reader)
def columnNames = parseColumnNames(args, csvReader)
new CsvIterator(columnNames, csvReader) {
def next() {
throwsExceptionIfClosed()
new PropertyMapper(columns: this.columns, values: this.nextValue) {
def propertyMissing(String name) {
def index = this.columns[name]
if (index != null) {
values[index]
} else {
return null
}
}
}
}
}
}
}
Making things private (as opposed to protected) in an object language is extremely anti-social, because it prevents people from inheriting and expanding the class. For example, I wrote the below code to try and overcome issue #48 (i.e. stop getProperty() from throwing an exception), but it failed to compile because the members of CsvIterator are private. Don't do that. Make all data members protected.