in reply to Re: constructing dynamic class definitions at compile time (from schema definition)
in thread constructing dynamic class definitions at compile time (from schema definition)

Actually , its tight coupling that I'm trying to avoid.

The business problem is this: I'm loading a bunch of data into a database via the .bcp mechanism. The data is loaded into a "raw" table, and from there I sql over the raw table and insert into a more 'refined' version of the table.

To represent this, I have a RawTable class, whose attributes are the columns of the corresponding raw table. Every time I add / remove a column, I have to change the class definition of the RawTable ( too tightly coupled ). If the class builds its definition from the raw table schema, then I never have to change the RawTable class; it picks up the changes automatically.

Thus, if the schema changes (ie remove/add a column), exactly the _reverse_ happens to what you described above: I have to change _no_ code.

Thus in this case, I don't have to worry about the schema and application being too closely coupled; this close coupling is actually a Good Thing.

Granted, for larger problems, all of your points above are quite valid.

  • Comment on Re: Re: constructing dynamic class definitions at compile time (from schema definition)

Replies are listed 'Best First'.
Re3: constructing dynamic class definitions at compile time (from schema definition)
by dragonchild (Archbishop) on Jul 25, 2002 at 18:48 UTC
    Fair enough. However, I would still say that you shouldn't dynamically generate a class from a table.

    Let's say that a column does change in your RawTable. The corresponding API of the RawTable class changes. How are the clients of that class supposed to know that the API has changed? What if it's a column that disappears? Your API contract is now invalid. Not good.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.