KevinSimonson wrote:
So I created an abstract class called<SearchResult> that has no
In the real world, when there's a class like this, there's usually some
meta data that can decode which type is being returned. As Arne points
out, there's usually also a "getAsType" method. For example, the JDBC
object has various "getBoolean()" and "getBlob()" methods for accessing
database columns, as well as metadata describing the object.
While not the best over all (JPA is better, generally, than JDBC), it's
more structured that just an abstract class with no methods.
I might say that no methods = interface (called a mixin), but I think
the potential to add common methods here is high. So, use a base class
so that you don't get tripped up by Java's single inheritance. It's the
most conservative approach in this case.
The OP's approach seems somewhat hackish, based on the paucity of information provided so maybe it isn't. Would it work to make the varying type a generic parameter?