While developing an app some time ago, I had an interesting (in my opinion) but wrong solution to a problem I had.
Basically I was implementing 3 kinds of table models which where similar, but had different numbers of columns, the app would request the needed table model from a factory class, which would intanciate a needed table model based on the parameter I would send to it. All 3 table models would inherit from one class (which extended TableModel).
Now, the solution I came up with on paper was to declare an abstract static int in the parent class, and a function getColumnCount would return it. The constant itself would be declared in the inheriting classes (I use it in other functions as well). This way I wouldn't have to have getColumnCount function in every extending class. below is something that it could have looked like:
As you know
Java does not allow abstract fields.
Is there a way to implement something like this is Java, without actually having to retype the getColumnCount() function everywhere?
And does anyone knows the OO reason why the static fields can not be abstract?
[ January 19, 2004: Message edited by: Yuriy Grechukhin ]