I apologize in advance if this is really off the wall.
In my suncertify.db package, consider the two classes:
- Data.java (which implements the DB interface provided by Sun)
- DataAdapter.java
I have my Data class implemented such that it will work with any database that follows the schema provided by sun (magic cookie, field info, etc). So, for example, using my Data class with another database file that has a different number of fields, different field lengths, etc. would work fine. It deals with records as defined by the schema.
My DataAdapter class is more program specific. It deals with records as instances of contractors. (6 fields: Name, Location, Specialties, Size, Rate, Owner).
I decided to write a Contractor class that will wrap up a record and its record number, which can be sent to my ContractorTableModel class. It is fine to use this Contractor class in DataAdapter, but using it in Data would make my Data implementation program-specific, which i would like to avoid.
However, I would like to be able to wrap a record and it's record number in Data.java. This isn't a problem: just create a class called Record. But since my Contractor class is a specific representation of a Record, then a Contractor IS A Record. No problem - my Contractor class simply extends Record.
So here's the problem: whenever I have a method that returns a Record/Collection of Records, it's located in my Data class. And whenever I have a method that returns a Contractor/Collection of Contractors, it's located in my DataAdapter class. But my DataAdapter class always calls the methods of my Data class, and NOT the other way around.
So, for example, consider the following methods:
Is this bad style? I already know that it's probably going a bit overboard, but is it bad style? I'm returning a Collection of Records from the method in the Data class, pulling the Records out, converting them to Contractors (which are Records), putting them in a new collection, and then returning the new Collection. I can't use a cast because the objects in the Collection from Data weren't origionally created as Contractors: they were created as Records.
Is this bad style, too much work, look good, or am I
crazy?