groovycsv icon indicating copy to clipboard operation
groovycsv copied to clipboard

Don't make members private

Open xpusostomos opened this issue 3 years ago • 1 comments

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
                                }
                            }
                        }
                    }
                }
            }
        }

xpusostomos avatar Apr 27 '21 07:04 xpusostomos

@xpusostomos why you don't send a PR or make a fork to fix it?

ppazos avatar Dec 30 '22 01:12 ppazos