.NETGURU
Object Design Question
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngarchitecture' list.


James Yang
I found this on the list archieve./..and the answers to this question really
didn't explain why? so im posting it again.

Thank you

----------------------------------------------------------------------------
------------------------------
Most of the samples web apps that I've seen posted do not specifically
create "entity" objects as one might do in Java. Instead, the C# objects
typically contain methods that return the equivalent data as a datareader or
resultset of some sort. I.e. the data is frequently contained in a system
object. For example instead of instantiating a Person object with
attributes like Name, Address, Age etc, and filling that entity object with
appropriate data via a seperate data access class the typical C# scenario
that I've seen -like Petshop for example- has classes with methods like the
example below. My question is simply why? Why use this approach? Why not
define a interface, derive an entity object from that interface, fill that
entity with data from an external mechanism and as the case would be in the
example below - return a collection or array or some other structure of
multiple objects to the caller.

Excerpt from Petshop sample:
----------------------------------------------------------------------------
--------------------------------------------

public class Item {
public SqlDataReader GetList(string prodid) {

SqlDataReader dataReader = null;

try {

// create data object and params

Database data = new Database();

SqlParameter[] prams = { data.MakeInParam("@prodid",
SqlDbType.VarChar, 10, prodid) };

// run the stored procedure

data.RunProc("upItemGetList", prams, out dataReader);

}

catch (Exception ex) {

Error.Log(ex.ToString());

}

return dataReader;

}

etc etc etc.

Reply to this message...
 
    
Deyan Petrov
Hi,

I personally don't like this approach, which is also present in Duwamish.
This is a dirty but very performant design.
I design my application with entity objects and custom entity object
collections. I am very satisfied by the custom business objects approach I
am using. First I started with the DataSet centric approach, tried the
strongly typed Datasets also, but it sucked.

Regards,
Deyan Petrov

----- Original Message -----
From: "James Yang" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 10:50 AM
Subject: [aspngarchitecture] Object Design Question

> I found this on the list archieve./..and the answers to this question
really
[Original message clipped]

Reply to this message...
 
    
jimmy.nilsson@jnsk.se (Jimmy Nilsson)
Hi James,

I've seen the approach of "instantiating a custom object for each row in the
resultset" being used in several VB6-written server-side applications, with
horrible results from a performance and scalability perspective. Perhaps the
reason for the somewhat slow adoption of the same approach in .NET is
because "everybody" knows that it will work still in reality too to just
transport the data in a system-provided container and therefore stays with
the safe approach for the moment?

And, as always, it's a matter of tradeoffs...
:-)

I hope I was successful in not expressing any opinions of my own in this
email.
;-)

BTW, there are some examples to be found about using typed datasets as the
basis for entity objects, aren't there?

Best Regards,
Jimmy
###

----- Original Message -----
From: "James Yang" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 10:50 AM
Subject: [aspngarchitecture] Object Design Question

> I found this on the list archieve./..and the answers to this question
really
[Original message clipped]

Reply to this message...
 
    
Deyan Petrov
Hi Jimmy,

The performance of custom object collections is not horrible at all.
In the Retrieve method a DataReader fills the custom collection - the same
happens when a DataSet is filled from the database.
There is another performance drawback here - that you have to make sometimes
multiple roundtrips to the database, instead of 1, but this is the real
tradeoff - between fine granularity of the business tier (flexibility and
reusability) and speed.

Regards,
Deyan Petrov

----- Original Message -----
From: "Jimmy Nilsson" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 11:25 AM
Subject: [aspngarchitecture] Re: Object Design Question

[Original message clipped]

Reply to this message...
 
    
Rich Denis
When ever I have tried to load a collection from a record set of say
10,000, I never got good performance. But on smaller collections it was
just fine. Maybe its just a mater of practicality. =20

-----Original Message-----
From: Deyan Petrov [mailto:Click here to reveal e-mail address]=20
Sent: Tuesday, June 18, 2002 4:38 AM
To: aspngarchitecture
Subject: [aspngarchitecture] Re: Object Design Question

Hi Jimmy,

The performance of custom object collections is not horrible at all. In
the Retrieve method a DataReader fills the custom collection - the same
happens when a DataSet is filled from the database. There is another
performance drawback here - that you have to make sometimes multiple
roundtrips to the database, instead of 1, but this is the real tradeoff
- between fine granularity of the business tier (flexibility and
reusability) and speed.

Regards,
Deyan Petrov

----- Original Message -----
From: "Jimmy Nilsson" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 11:25 AM
Subject: [aspngarchitecture] Re: Object Design Question

[Original message clipped]


[Original message clipped]

| [aspngarchitecture] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngarchitecture.asp =3D JOIN/QUIT=20
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
    
jimmy.nilsson@jnsk.se (Jimmy Nilsson)
Hi Deyan,

[Original message clipped]

Sorry, I was unclear. What I meant was when you used that approach of custom
collections in VB6, then performance was horrible (when the collections was
used over process boundaries). Perhaps that knowledge is still used in .NET,
even though the situation is totally changed in .NET.

> There is another performance drawback here - that you have to make
sometimes
[Original message clipped]

Well, there is also some overhead in speed to fill the custom collection
instead of just letting the consumer use the datareader. OK, I don't use the
approach of letting the presentation tier use a datareader, but it is a
tradeoff.
:-)

Best Regards,
Jimmy
###

[Original message clipped]

Reply to this message...
 
    
Deyan Petrov
Hi Rich,

10 000 objects sounds very bad for you design. Why would you need 10 000
objects??? The user cannot see all of them at once. You should redesign and
use/return/show less objects ...

Regards,
Deyan Petrov

----- Original Message -----
From: "Rich Denis" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 1:32 PM
Subject: [aspngarchitecture] Re: Object Design Question

When ever I have tried to load a collection from a record set of say
10,000, I never got good performance. But on smaller collections it was
just fine. Maybe its just a mater of practicality.

-----Original Message-----
From: Deyan Petrov [mailto:Click here to reveal e-mail address]
Sent: Tuesday, June 18, 2002 4:38 AM
To: aspngarchitecture
Subject: [aspngarchitecture] Re: Object Design Question

Hi Jimmy,

The performance of custom object collections is not horrible at all. In
the Retrieve method a DataReader fills the custom collection - the same
happens when a DataSet is filled from the database. There is another
performance drawback here - that you have to make sometimes multiple
roundtrips to the database, instead of 1, but this is the real tradeoff
- between fine granularity of the business tier (flexibility and
reusability) and speed.

Regards,
Deyan Petrov

----- Original Message -----
From: "Jimmy Nilsson" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 11:25 AM
Subject: [aspngarchitecture] Re: Object Design Question

[Original message clipped]

| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Deyan Petrov
Hi Jimmy,

In some cases I am contemplating of using a hybrid approach, without loading
collections, in case of a report for example. Still I think it will be the
same - when you load a DataSet you create all those columns/rows objects....

Regards,
Deyan Petrov

----- Original Message -----
From: "Jimmy Nilsson" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 12:00 PM
Subject: [aspngarchitecture] Re: Object Design Question

[Original message clipped]

Reply to this message...
 
    
jimmy.nilsson@jnsk.se (Jimmy Nilsson)
Hi Deyan,

Unfortunately I don't know how the dataset is implemented, but I don't think
it *has to* instantiate an object for each row etc. A flyweight pattern
could be used instead so that objects are created when needed from an
underlying (and less expensive) representation. Could anybody sched some
light on how datasets are implemented internally?

Best Regards,
Jimmy
###
----- Original Message -----
From: "Deyan Petrov" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 2:22 PM
Subject: [aspngarchitecture] Re: Object Design Question

[Original message clipped]

Reply to this message...
 
    
Rich Denis
The point was not 10000 objects. It was that loading data into object
into a collection only to be bound to form elements is not so bad on
small scale collections but that on larger collections, you can
definitely see the performance hit. First you have to loop your data
and make objects then when you bind that collection it is looping the
same data again. Even on a collection of 100 objects it is going to be
slower than binding directly to the original data source. In the
collections that I have written I have specified a bool flag on the
constructor that told the collection to pre-load itself or not. There
is also a property accessible that represents the data of the
collection. That way if I was only going to use the collection to bind
it to a form element I would not waste my time or CPU loading the
collection. If at any point I needed data then I could get just the data
I needed. It sounds similar to the approach that others are using as
well. It works really well cause you get the benefit of OO design and
reusable objects and performance when you need it.

R

-----Original Message-----
From: Deyan Petrov [mailto:Click here to reveal e-mail address]=20
Sent: Tuesday, June 18, 2002 7:20 AM
To: aspngarchitecture
Subject: [aspngarchitecture] Re: Object Design Question

Hi Rich,

10 000 objects sounds very bad for you design. Why would you need 10 000
objects??? The user cannot see all of them at once. You should redesign
and use/return/show less objects ...

Regards,
Deyan Petrov

----- Original Message -----
From: "Rich Denis" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 1:32 PM
Subject: [aspngarchitecture] Re: Object Design Question

When ever I have tried to load a collection from a record set of say
10,000, I never got good performance. But on smaller collections it was
just fine. Maybe its just a mater of practicality.

-----Original Message-----
From: Deyan Petrov [mailto:Click here to reveal e-mail address]
Sent: Tuesday, June 18, 2002 4:38 AM
To: aspngarchitecture
Subject: [aspngarchitecture] Re: Object Design Question

Hi Jimmy,

The performance of custom object collections is not horrible at all. In
the Retrieve method a DataReader fills the custom collection - the same
happens when a DataSet is filled from the database. There is another
performance drawback here - that you have to make sometimes multiple
roundtrips to the database, instead of 1, but this is the real tradeoff
- between fine granularity of the business tier (flexibility and
reusability) and speed.

Regards,
Deyan Petrov

----- Original Message -----
From: "Jimmy Nilsson" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 11:25 AM
Subject: [aspngarchitecture] Re: Object Design Question

[Original message clipped]


[Original message clipped]

| [aspngarchitecture] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngarchitecture.asp =3D JOIN/QUIT=20
| http://www.asplists.com/search =3D SEARCH Archives

| [aspngarchitecture] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngarchitecture.asp =3D JOIN/QUIT=20
| http://www.asplists.com/search =3D SEARCH Archives

| [aspngarchitecture] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngarchitecture.asp =3D JOIN/QUIT=20
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
    
Deyan Petrov
Hi Rich,

That's the hybrid approach I was referring to previously.
It's good, but let me ask you - what will be the container of your data
property? A DataSet? The construction of a DataSet is also not the fastest
thing in the world, have this in mind.
I think that loading a collection of objects from a DataReader is the
fastest thing to do, and that it's not good to pass around a DataReader to
the UI and let it iterate on it as slow as it likes, as the connection is
open all the time and scalability suffers much. A quick load from the
IDataReader to the custom collection, after that release the connection.
I really think that whether you load the data into a custom collection,
DataSet, ArrayList, it creates internally objects. Maybe a simple
stack-based value type would be the fastest, but I am not sure...

Regards,
Deyan Petrov

----- Original Message -----
From: "Rich Denis" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 4:19 PM
Subject: [aspngarchitecture] Re: Object Design Question

The point was not 10000 objects. It was that loading data into object
into a collection only to be bound to form elements is not so bad on
small scale collections but that on larger collections, you can
definitely see the performance hit. First you have to loop your data
and make objects then when you bind that collection it is looping the
same data again. Even on a collection of 100 objects it is going to be
slower than binding directly to the original data source. In the
collections that I have written I have specified a bool flag on the
constructor that told the collection to pre-load itself or not. There
is also a property accessible that represents the data of the
collection. That way if I was only going to use the collection to bind
it to a form element I would not waste my time or CPU loading the
collection. If at any point I needed data then I could get just the data
I needed. It sounds similar to the approach that others are using as
well. It works really well cause you get the benefit of OO design and
reusable objects and performance when you need it.

R

-----Original Message-----
From: Deyan Petrov [mailto:Click here to reveal e-mail address]
Sent: Tuesday, June 18, 2002 7:20 AM
To: aspngarchitecture
Subject: [aspngarchitecture] Re: Object Design Question

Hi Rich,

10 000 objects sounds very bad for you design. Why would you need 10 000
objects??? The user cannot see all of them at once. You should redesign
and use/return/show less objects ...

Regards,
Deyan Petrov

----- Original Message -----
From: "Rich Denis" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 1:32 PM
Subject: [aspngarchitecture] Re: Object Design Question

When ever I have tried to load a collection from a record set of say
10,000, I never got good performance. But on smaller collections it was
just fine. Maybe its just a mater of practicality.

-----Original Message-----
From: Deyan Petrov [mailto:Click here to reveal e-mail address]
Sent: Tuesday, June 18, 2002 4:38 AM
To: aspngarchitecture
Subject: [aspngarchitecture] Re: Object Design Question

Hi Jimmy,

The performance of custom object collections is not horrible at all. In
the Retrieve method a DataReader fills the custom collection - the same
happens when a DataSet is filled from the database. There is another
performance drawback here - that you have to make sometimes multiple
roundtrips to the database, instead of 1, but this is the real tradeoff
- between fine granularity of the business tier (flexibility and
reusability) and speed.

Regards,
Deyan Petrov

----- Original Message -----
From: "Jimmy Nilsson" <Click here to reveal e-mail address>
To: "aspngarchitecture" <Click here to reveal e-mail address>
Sent: Tuesday, June 18, 2002 11:25 AM
Subject: [aspngarchitecture] Re: Object Design Question

[Original message clipped]

| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
 
System.Collections.ArrayList
System.Data.DataSet
System.Data.IDataReader
System.Data.SqlClient.SqlDataReader
System.Data.SqlClient.SqlParameter
System.Data.SqlDbType




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification