nixie wrote:
I do not entirely agree on that.
1) it is object orientated, only the objects look a little different (instead of returning an id for the province I return a provincename)
2) That is true, but the same goes for retrieving duplicate id's although the id's might use less Kb
3) Thats the same argument you gave under point 2
4) So what
5) You must always go to the database to get the provinceinfo, one way or another
6) Í will call the database only once, and in one call I get all the data
7) At a certain point things will become difficult, ofcourse. But it would also become difficult if you put that code in vb. So wether you would use difficult code in a stored procedure or in your vb code, yoú will always end up with difficult code at some point.
1) tenet of object oriented programming - choose composition over inheritance
By melding the two objects into one, you end up with one object trying to manage two things. in a composition design, you would have one object that may contain many other related objects. the provinceinfo example is quite simple so it may not seem worth the extra effort but i have table that uses up to 10 foreign keys for related entities. so anytime i want to look at my object i should use a join to pull aaaallll that data back?? no way. i pull up my object and i fill my object graph only as deeply as required. In some instances, this does result in extra hits to the database but by far our database activity has been significantly reduced.
2) i wouldnt consider duplicate id's to be duplicate data.
3) Duplicate data consumes additional memory. duplicate data also increases network traffic from the webserver to the db server. so duplicate data can affect your performance in more ways than one.
4) You decision to create a query that joins two objects creates a new object. now you must manage the new object. what happens when you need the original data but you dont need the province info? do you just use your query and pull provinceinfo anyways. what happens when you need companyinfo and provinceinfo, or companyinfo but not provinceinfo. as you begin to create related tables, the number of permutations for queries begins to become exponential. you end up spending a lot of your time setting up and managing these special case queries.
5) in the model i propose, i would go to the database theoretically once per application run to get the provinceinfo data. not once per page. highly reusable data is held in cache and i only need to go to the database when the data is missing from the cache. the farther away from your webserver you need to go to get data, the more of a performance boost this will give your application.
6) There are [at least] two performance metrics to consider when building applications. a) how quickly can i build it. b) how will it perform. if you create a unique query for every use case you will spend a lot of your development time coding and managing queries. In my model, i may call the database once for that data and not need to hit the database again until the app restarts.
7) i disagree. i cant remember the last time i wrote a stored procedure or even a query. I use some highly reusable core classes that we created to get access to all our data. our application coding has been immensely simplified because we work with objects and not database tables. the details how these objects ultimately persist themselves is of no concern to the application. it is of concern only to the data access layer. people get concerned that adding a "layer" may affect performance and indeed it may. in our case we saw a 40+% performance increase at our data layer when we starting using business entity collections vs datasets. This performance increase does not include any data caching. We have also experienced a coding performance increase as these objects have been created to be highly resuable. Code should not become overly difficult. When it does, it is time to refactor.
Mike Banavige
~~~~~~~~~~~~
Need a site code sample in a different language? Try converting it with:
http://converter.telerik.com/