1
\$\begingroup\$

I have a GUI that contains a Table Object (for displaying columns of data) and a Table Model. The Table Object contains the Table Model.

Is it better to store the Table Model as a object in the User interface or de-reference it as needed? Is there any performance gain keeping it separate? If there is, is it a good design to implement this?

For example:

public GUI {
    private Table table;
    private TableModel model;

    public UI() {
        this.table = new Table();
        this.model = table.getModel();
        }
        public void actionPerformed() {
           // Performance improvement 
           // without having to de-reference it from table
           model.setRowLimit();
        }
    // OR
    public void actionPerformed() {
        // Slower but is it better OO Design
        table.getModel().setRowLimit();
    }
}

The GUI has 10 public methods exposed where the model could be updated or changed.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

There will be no difference in performance whatsoever between the two approaches.

I would suggest you don't break the responsibility principle and leave the handling of the tablemodel to the Table class.

One remark though: if there are additional computations done in getTableModel() aside from a plain setter, you will bypass these if your create the local variable. This may or may not be something you desire.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.