OOP Question

C

Chris

Can someone tell me the OOP way to code classes for small tables of data?

For example, i'm loading several tables that will be stored in the
current.cache of an asp.net app. One table is credit cards; another is
countries.

Do i need two classes for each of these? A parent and a child class (similar
to tables and table in ado.net) or is there a better way to do it?

See code below...

Thanks,

Chris
BugMonitor.com

Public Class Category
Public Attrib1 As Integer
Public Attrib2 As String
End Class

Public Class Categories
Public Shared Category As Category()
Public Shared Count As Int16

Public Shared Function GetAll() As Categories
Dim bCategory As Category
While dr.Read
bCategory = New Category
With bCategory
.Attrib1 = val1
.Attrib2 = val2
End With
al.Add(bCategory)
Count += 1S
End While

Dim bCategories As New Categories
bCategories.Category = DirectCast(al.ToArray(GetType(Category)),
Category())

Return bCategories
End Function

End Class
 
O

One Handed Man \( OHM - Terry Burns \)

The question comes to my mind, Why dont you simply use the ADO.NET classes,
or if you need more functionality, simply inherit them and add your own
custom bits.

Or have I missed something ?
 
C

Chris

If you're talking about using datatables, then that is the way i'm used to
doing it, but i understood that datatables were not intended for the web
(less efficient), so i was trying to learn the OO way of doing it.

Thanks,

Chris
 
O

One Handed Man \( OHM - Terry Burns \)

You should consider a Custom Control, this way you can have full control
over the rendered output for it and include whatever data storage you need
 
C

Chris

Hey Terry,

Thanks for the response.

I'm not concerned with presentation at this point. I'm focusing on the data
and business layers. Some of these classes may not have a presentation
layer -- just used by other classes.

Thanks,

Chris
 
O

One Handed Man \( OHM - Terry Burns \)

OK, back to your original question

Tables and Tables are closely related. It is natural to contain a Table in
Tables. As far as DataTables not being suitable for the web from an
efficiency point of view, do you have impirical evidence to support this.?

I personally 'have' used DataTables as the base for display, and of course
DataGrid's to display, I have not noticed any particular issues with speed.
 
J

Jay B. Harlow [MVP - Outlook]

Chris,
Curious, where did you get that idea?

I understand that datatables were explicitly designed for both the Web &
Windows!

Remember DataTables (only) support XML, which is a web friendly format!

Hope this helps
Jay
 
J

Jay B. Harlow [MVP - Outlook]

Chris,
As OHM suggested, the OOP way to code classes for small tables of data is
System.Data.DataTable, I would consider keeping both of your DataTables in a
System.Data.DataSet, specifically a Typed DataSet.

Martin Fowler's book "Patterns of Enterprise Application Architecture" from
Addison Wesley http://www.martinfowler.com/books.html#eaa explains when you
may want to use a traditional Domain Model & Data Mapper pattern:
http://www.martinfowler.com/eaaCatalog/domainModel.html
http://www.martinfowler.com/eaaCatalog/dataMapper.html

verses a Table Module & Data Gateway patterns:
http://www.martinfowler.com/eaaCatalog/tableModule.html
http://www.martinfowler.com/eaaCatalog/tableDataGateway.html

Martin also offers a couple of other useful patterns that can be used
instead of or in conjunction with the above patterns.

FWIW: The System.Data.DataTable is an implementation of a Record Set
pattern:
http://www.martinfowler.com/eaaCatalog/recordSet.html

Rockford Lhotka's book "Expert One-on-One Visual Basic .NET Business
Objects" from A! Press provides a pre-implemented variation of Fowler's
Domain Model & Data Mapper patterns.
http://www.lhotka.net/



Generally if there is no real logic behind my domain objects, I would use
the DataSet OOM coupled with a Table Module & Data Gateway patterns. As the
classes themselves are not really living up to their potential! :) The
Table Module & Data Gateway patterns may be implemented in a single class or
two classes. Again I would consider using a Typed DataSet.

However if there is significant logic behind my domain objects, I would then
favor the Domain Model & Data Mapper patterns.

Depending on the needs of the project I would consider Fowler's other
patterns...

Hope this helps
Jay
 
C

Chris

Jay,

I heard the idea from a former extremelogic MCT. He seemed pretty emphatic
that datatables are overused on the web and that they were designed for
winform apps and are heavy for web apps.

Thanks,

Chris
 
C

Chris

Thanks Jay. I'll take a look at these authors and their recommended
patterns.

Regards,

Chris
 
C

Chris

Tables and Tables are closely related. It is natural to contain a Table in
Tables. As far as DataTables not being suitable for the web from an
efficiency point of view, do you have impirical evidence to support this.?

I personally 'have' used DataTables as the base for display, and of course
DataGrid's to display, I have not noticed any particular issues with
speed.

No. As i said before, using datatables is what i'm used to doing. I heard
the idea from a former extremelogic MCT. He seemed pretty emphatic that
datatables are overused on the web and that they were designed for winform
apps and are heavy for web apps.

So i was trying to do it the OO way, but you guys are saying that my
original methods (datatables) are preferred over parent/child classes.

Thanks for your input!

Chris
 
O

One Handed Man \( OHM - Terry Burns \)

No worries, good luck with it, and please do come back and tell us how you
got on.
 
C

Chris

Thanks, I will.

Chris

One Handed Man ( OHM - Terry Burns ) said:
No worries, good luck with it, and please do come back and tell us how you
got on.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .


Table wrote
 
J

Jay B. Harlow [MVP - Outlook]

Chris,
I normally write programs that are "correct" first, then optimize for
performance later. Only when a specific routine is proven to be a
performance problem via profiling tools.

As I indicated in my other post I would choose DataSet or Domain model based
on the needs of the Domain objects.

If DataSet was shown to be a performance problem based on profiling, I would
then review the specific cases where the performance is an issue and change
them...


Of course I try to be well read on OOP Patterns to help choose the "correct"
plan for the current solution...

Hope this helps
Jay

Chris said:
Jay,

I heard the idea from a former extremelogic MCT. He seemed pretty emphatic
that datatables are overused on the web and that they were designed for
winform apps and are heavy for web apps.

Thanks,

Chris
<<snip>>
 

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

Top