473,382 Members | 1,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Class design

I have always been told that I should only get the data I need for each web
page, so my quandary is set against that backgound.

Let's say I have a User class with 10 properties. I have a private method
that populates all of these properties with values from the database.
However, I may only need to display two of the properties on a web page
(name and last login time, for example). Coming from a pure ADO/ADO.NET
background, where I would only retrieve these two values and plug them into
their place on the page, this seems a bit wasteful to me. I can see that in
the event I might need to display more properties, I only need to make one
small change in the ASP.NET page, as the values are already available, but
should I really be thinking about creating other private methods that
instantiate a User object but only populate some of the properties?

Is this part of the trade off I should accept when using an OOP approach, or
should I be looking at it differently?

Sep 21 '08 #1
1 1449
On Sun, 21 Sep 2008 10:06:03 -0700, Mike
<ne************@newsgroups.invalidwrote:
[...]
Let's say I have a User class with 10 properties. I have a private
method
that populates all of these properties with values from the database.
However, I may only need to display two of the properties on a web page
(name and last login time, for example). Coming from a pure ADO/ADO.NET
background, where I would only retrieve these two values and plug them
into
their place on the page, this seems a bit wasteful to me. [...]

Is this part of the trade off I should accept when using an OOP
approach, or
should I be looking at it differently?
Unfortuantely, there's not enough detail in your question to allow us to
fully understand just how "wasteful" that design might be or what
alternatives might be most appropriate.

However, there's at least a few alternatives you might use:

-- You could allow the "User" class to retrieve the property values
dynamically as needed. That way, the class itself can be instantiated
without retrieving any actual data, and then as each property is accessed,
the relevant data would be retrieved. You'd probably want to cache the
data so that the retrieval happens only once per property per instance.

-- You could allow the properties to be "optional" in the sense that
when you construct the "User" instance, you pass a list of property names
to be populated. Then only the data for those properties would be
retrieved; if the client tries to access any of the other properties,
throw an exception or return some default value.

-- You could skip having properties altogether, and instead make each
value something that is retrieved by name, using a dictionary. This could
be in the form of an explicit method in the class to do the retrieval, or
an indexer on the class, or even just by having a single property that
returns the dictionary itself. As with the #2 option above, you'd pass a
list of desired properties to the constructor, and only those properties
would be put in the dictionary.

Hope that helps.

Pete
Sep 21 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Aguilar, James | last post by:
My previous example used the concept of a Shape class heirarchy, so I will continue with that. Suppose I have something like fifty different shapes, and I am trying to instantiate one of them. ...
15
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for...
3
by: fernandez.dan | last post by:
I'm still learning how to use Object Oriented concepts. I'm have a basic question dealing with design. I have two classes that deal with I/O pertaining to network and usb that inherit from an...
9
by: David A. Osborn | last post by:
I have a set of classes that each have an enumeration in them, and based on dynamic input I need to access a different enumeration. For example Three classes Class_A, Class_B, and Class_C that...
3
by: Trammel | last post by:
Hi, I recently upgraded to VB.net from VB6.. and woah... I feel lost :¬O One of my reasons for upgrading is I was told that VB.net can do class inheritance and subclassing easier. ...
6
by: Orgun | last post by:
Hi, I sent this message to the moderated c++ group too but it is waiting for moderator approval and I wanted to send here too. I am new to Design Patterns. I want to write a simple...
25
by: David Sanders | last post by:
Hi, As part of a simulation program, I have several different model classes, ModelAA, ModelBB, etc., which are all derived from the class BasicModel by inheritance. model to use, for example...
6
by: JoeC | last post by:
I have a question about designing objects and programming. What is the best way to design objects? Create objects debug them and later if you need some new features just use inhereitance. Often...
5
by: pgrazaitis | last post by:
I cant seem to get my head wrapped around this issue, I have myself so twisted now there maybe no issue! Ok so I designed a class X that has a few members, and for arguments sake one of the...
6
by: Bhawna | last post by:
I am into c++ code maintenance for last 3-4 years but recently I am put into design phase of a new project. Being a small comapany I dont have enough guidance from seniors. Currently I am into a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.