7 ms·
Soooo one row of a collection represented as an object instance of a collection of instances is bad? Why?
by scient 11y ago
Soooo one row of a collection represented as an object instance of a collection of instances is bad? Why?
- porker 11y agoNo not at all :) Slavishly mapping a row in a database table to an application object is bad. Off the top of my head, an example could be a Product, where the tables are something like: product - main product details product_option - options (e.g. Size, Colour) product_option_values - values for that specific option instance In my application I don't care about the database structure - whether the tables are normalised or storing everything in one huge serialized blob (or CouchDB, or ElasticSearch or... you get the picture). Instead you want to get the options and save changes straight back when editing the product. Now this is where my example breaks down as the Product needs to 'know' about what options are available (either to provide a nice API or to know what to display in the UI) and my schema doesn't allow for that (save a Product.getAllOptions() method) but I'll leave that as an exercise for my reader :)