Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't make members private #49

Open
xpusostomos opened this issue Apr 27, 2021 · 1 comment
Open

Don't make members private #49

xpusostomos opened this issue Apr 27, 2021 · 1 comment

Comments

@xpusostomos
Copy link

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
                                }
                            }
                        }
                    }
                }
            }
        }
@ppazos
Copy link

ppazos commented Dec 30, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants