Skip to content

private vs. protected in visitor / deparser #675

@ted-johnson

Description

@ted-johnson

Is there a reason why deparsers and the buffer are private in the visitor and deparser classes?
Shouldn't they be protected instead?

For example, I would like to insert some extra output during Insert statement deparsing.
But the StatementDeParser class defines its members as:
public class StatementDeParser implements StatementVisitor {
private ExpressionDeParser expressionDeParser;
private SelectDeParser selectDeParser;
private StringBuilder buffer;
The InsertDeParser defines these members similarly.

If I try to write
@OverRide
public void visit(Insert insert) {
buffer.append("-- an insert statement");
...
}
I get an error saying that buffer is private.
There is a getBuffer method, but using it makes the code cumbersome.
There is no get method for expressionDeParser or selectDeParser, so its much harder
to write code which accesses or manipulates these members.

The value of the visitor and deparser framework would seem to be the ability to modify
selected parts of the deparsing by subclassing and overridding selected methods.
Since these classes are supposed to be subclassed, shouldn't important member variables
be protected instead of private?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions