views:

142

answers:

2

If I have a business object with 50 fields, and I need to populate something like a drop down list or gridview with only 3 fields from the business object to allow quick browsing.

Is it best practice to load the fully populated BO then just grab the few required fields in your presentation layer ?

It seems inefficient to populate a collection of Bo's that size but the only other ways would seem to be to return partially populated BO's with just the fields you need for a particular UI which would be hard to manage if you have alot of similar UI requirements, or make a baseclass like MyBusinessObjectHeader that contains the fields then make MyBusinessObject inherit it and implement the rest of the fields but this would tie it your UI too much it seems.

Whats the best practice for this type of situation ?

A: 

There are a lot of frameworks out there that do this sort of o/r mapping you're talking about.

You're trading a little more overhead for ease of use and robust configuration.

See Hibernate or NHibernate if you're using .net.

Nathan
+2  A: 

I make a separate readonly list of readonly digest objects (or structs) that are lightweight and cannot be manipulated. The collection can be customized for whatever needs you might have as normal. Retrieval of a full object can be used by passing a "digest" object to a type conversion, or factory or constructor - whatever techniques you are using.

Note that this is an optimization which only happens when a collection of full-blown objects is simply getting too slow. It can easily be created at that point. Generally such classes are not created until necessary.

Cade Roux