views:

249

answers:

3

When should I rather implement TableModel and when should I extend AbstractTableModel?

+3  A: 

When should I rather implement TableModel

When you need a complete clean sheet implementation of the table model and/or you have to provide something that by the nature of your model doesn't exists yet or doesn't fit.

and when should I extend AbstractTableModel?

When you can reuse the existing structure and methods provided by the abstract class and/or it would easier for you to implement it.

The idea is, if you can re-use it, do so. If you can't, implement from scratch.

By inheriting AbstractTableModel you'll be imlementing the TableModel interface anyway, it just will be easier.

OscarRyz
+1  A: 

AbstractTableModel provides default implementations for many of the methods defined in TableModel. If you don't need any custom behavior, then you can simply extend AbstractTableModel. Also, if your model already extends a different base class, then it would be appropriate just to implement TableModel.

Ken Liu
+1  A: 

AbstractTableModel has implementation for the handling of TableModelListeners, including the firing of TableModelEvents. If you want to handle that yourself, then there really is no reason to extend. Outside of that code, the other code doesnt add any benefit other than the stubbing out of methods declared in the interface.

akf