Class Design Question for 3-tier web app

C

Chumma Dede

Hi,

We are building a 3-tier web-app and are currently in planning phase.
At the business layer, I have a class which has a 2-d array which can
potentially hold thousands of rows. The thing is on the UI, I would
like to implement some kind of paging to display only N rows at a time
from this 2-d array.

I only want to retrieve records for the current page from the database.
This way the object does not overload memory with all rows that are not
currently shown on the UI.

How should I handle this in the class design? Should I have a property
in the class which will hold the current page number? This class
represents a business object, so I am not keen on that solution.

Any suggestions on how to handle this while designing classes? We are
currently in the Planning phase, and this will be a great help.

Thanks,
JGP
 
J

john_teague

I would probably create a method for you businesslayer app that takes a
starting row and the number of rows to return.

If you are using a datagrid to display with paging enabled, it will
store the CurrentPageIndex and the PageSize.

Pass into your business layer GetPagedData( CurrentPageIndex*PageSize,
PageSize) or something to that effect. That will keep your
presentation logic and business logic separated.

BTW. This only reduces the memory requirements for the client, not
your server. Unless you are implement the paging at the database layer
(or wherever) all of rows will reside in memory on your server. I need
more specifics on where your data is coming from.

Also, instead of a 2d array you might consider a collection of objects.
It will be much easier to work with.

Hope this helps,
John
 
K

Kevin Spencer

How should I handle this in the class design? Should I have a property
in the class which will hold the current page number? This class
represents a business object, so I am not keen on that solution.

Good to see you giving this some thought! Actually, keeping track of the
current page number in the business class is not a bad idea, as the page
number is not related per se to the user interface, and is used to fetch
data from the data layer. It can be used by the interface as well, but that
is what business objects are for (to manipulate and provide data to the
interface).

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
P

peshekeedweller

john, just a question. Would there be any advantage to having 2 collections:
one to hold the current data (or a reference to it) until (if) it is to be
updated to the data store; and one to hold the next data to be sent to the
ui. Wouldn't that speed up the data display since you could fetch the next
data collection while the current data collection is being displayed to the
ui and you wouldn't have to make a round trip to the data store from the ui
(through the business layer) to get each page of data. Kinda like "chunking"
or "buffering", I guess.
 
J

john_teague

Well, the only way I can see the speeding things up is if you an async
call back to get the next set of results.

ArrayList CurrentResults;
ArrayList NextResults;

when you view CurrentResults, you need need to keep NextResults synched
as well, so you would always be making a trip to the datastore on the
same thread.

An async callback might speed things up a little bit, but not sure it
would be worth it. It really depends on the number of records your
dealing with, the web server and database server capabilities to
determine which approach.

The common argument at my place to work is that our database is stored
on a very powerful server, so do as much as you can there. However, I
think that only holds true for extreme number of records (and if you
have that many records, maybe that should be filtered first). If I'm
dealing with <= 1000 records, I would prefer to cache the entire
collection on the webserver and pull back exactly what I want from the
cached collection.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top