I have a generic data class that has a variable list of attributes - each representing a column in a table (name, type etc.). I have a class that reads data from the database and populates instances of the data class (e.g., there is a load(ID, tableName) method that returns an instance of the data for the given table).
I also have a bunch of classes that extend the above class - these represent actual tables and have the actual attributes of each table. these are used as POJOs with getters and setters.
What I want to be able to do is to "cast" the generic data class as a POJO - e.g. when my Data instance is returned, I'd like to map the data values for each column to the actual instance variables in the subclass.
What would be an ideal design for something like this.
If those objects all implement the same interface, try to declare them of that interface type, then maybe you can avoid the class cast.
Joined: Mar 26, 2009
Campbell Ritchie wrote:If those objects all implement the same interface, try to declare them of that interface type, then maybe you can avoid the class cast.
Thank you all for the reply (Sorry for the late ack, but I am new and I kept looking at 'My Posts' and it only shows my version )
The objects return a POJO that represents a 'table' with getters and setters for each field - the generic object has a map that holds reference to each field... I'll probably use a 'translator' service to map the mapped objects to actual attributes.