Suppose I have a Java or C# application in which I have classes like Book, Library, Author, ... and I want an easy way to map these items to database, or show them in a data grid.
I could implement interfaces for all these classes specifically for the data grid and for the database interaction, but this may mean quite some work whenever:
- a new class is added (e.g. Loaner, Publisher, ...)
- a new generic module is added (e.g. a reporting module in which the user may choose which information of the class to show in the report)
An alternative is to rely on the reflection capabilities of Java and C# and simply use this information to build the data grid and the database interface. Is this a logical approach or is it better not to rely on reflection and write explicit interfaces for every class-module combination (book-datagrid, book-database, book-report, library-datagrid, library-database, library-report, author-datagrid, ...)?
For the database-mapping, tools like Hibernate could be used, but does Hibernate also rely on reflection or do you have to implement an explicit interface for each of your classes as well to make use of Hibernate?