.NETGURU
OO class design question
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcs' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Francesco Sanfilippo
I am building an OO Business Logic Tier in C# for a big .NET application, a
community web site, ala Yahoo and MSN (but not quite that big). A core
object is the Member class, representing a signed in Member of the site.
When the Member object detects a sign-in, it loads some data for a user that
is used in a Control Panel type region, with live statistics. As users
click on links for details about control panel items (such as: newsletters
they belong to, emails they have received since last sign in, friends of
theirs that are online) the data is dynamically loaded from a SQL Server.

Here's an example of a design conundrum I am in:

A Member has a MemberAddress property which is a custom class called
MemberAddressCollection. MemberAddressCollection has an ArrayList as a
property, and that ArrayList holds MemberAddress structs which each
represent a single adress book entry. The MemberAddressCollection also
holds methods for Select/Insert/Update/Delete.

Does this seem like a good design? Does it help to use structs for the base
data holding objects (MemberAddress)?

Francesco

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com

Reply to this message...
 
    
Steve Sharrock (VIP)
Is your question about using structs centered around the fact that in
C#, types declared using struct are value types, and types declared
using class are reference type? I think you would need a compelling
reason to use struct over class, or at least be aware of how the two are
handled differently within the framework. But this is more of an
implementation issue, rather than design.

It sounds like a great project--have fun.

Steve Sharrock
programmer / designer
www.sharkcode.com

-----Original Message-----
From: Francesco Sanfilippo [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 03, 2002 11:45 AM
To: aspngcs
Subject: [aspngcs] OO class design question

I am building an OO Business Logic Tier in C# for a big .NET
application, a
community web site, ala Yahoo and MSN (but not quite that big). A core
object is the Member class, representing a signed in Member of the site.

When the Member object detects a sign-in, it loads some data for a user
that
is used in a Control Panel type region, with live statistics. As users
click on links for details about control panel items (such as:
newsletters
they belong to, emails they have received since last sign in, friends of

theirs that are online) the data is dynamically loaded from a SQL
Server.

Here's an example of a design conundrum I am in:

A Member has a MemberAddress property which is a custom class called
MemberAddressCollection. MemberAddressCollection has an ArrayList as a
property, and that ArrayList holds MemberAddress structs which each
represent a single adress book entry. The MemberAddressCollection also
holds methods for Select/Insert/Update/Delete.

Does this seem like a good design? Does it help to use structs for the
base
data holding objects (MemberAddress)?

Francesco

_________________________________________________________________
Join the world's largest e-mail service with MSN Hotmail.
http://www.hotmail.com

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

Reply to this message...
 
    
Richard Lowe
Hi Francesco,

[Original message clipped]

Hi Francesco, I think holding structs in an ArrayList is not generally what you
want to do. A C# struct will need to be boxed when inserted and unboxed to be
reconstituted into a stuct. A class in the same role would only need to be cast
from object to it's type. Structs also carry the risk of mis-use because they have
similar syntax, but different semantics from classes. Not a big deal, but it's out
there.

Now, you may have a compelling reason to use a struct - perhaps you have areas of
your application where the MemberAddress is desired as a value type. But if you
don't have a compelling reason, my choice would be either turn MemberAddress into a
class or replace the ArrayList property of your collection with a strongly typed
array of MemberAddress structs.

My 2p.
Richard

--- Francesco Sanfilippo <Click here to reveal e-mail address> wrote:
[Original message clipped]

__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com

Reply to this message...
 
 
System.Collections.ArrayList




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