473,404 Members | 2,137 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,404 software developers and data experts.

Single Class vs Multiple Class

I have many types of classes and I'm deciding whether to use a single
class or multiple classes for EACH type of class.

For an example:

User class has 3 classes associated with it:

User Class - Holds user properties. Has NO DB related methods (infact
has NO methods, only properties lol) etc
User Collection class - Holds a collection of user objects
User Manager Class - Performs all Saving/Loading/Creating operations
for a user object/collections.

Should I have all the functions/methods in User Manager class inside
the User class? I read some where that this is the BEST way and that I
should stop using a "manager" class because its the "old technique" of
coding back in the days of fortran.

Also, if I use a single class like User and store it in the
session...does it store all the methods and functions too? That could
be very costly.

A good thing I guess about having the 3 classes is that my DAL is
implemented in only the User Manager class.
So is single or multiple classes better?

May 29 '06 #1
4 2205
As to being an "old" technique .. this pattern is still happily alive and
well (known as the repository pattern) at the domain layer.

Seperating the data operations from the user object (which has its own
behaviors) is actually generally considerred a good thing as it will make
you code a bit more flexible. There is however a question as to whether or
not that flexibility is needed in your system. If it is not a simpler
pattern like Active Record might be better suited for you.

Cheers,

Greg Young
MVP - C#
<vz******@verizon.net> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
I have many types of classes and I'm deciding whether to use a single
class or multiple classes for EACH type of class.

For an example:

User class has 3 classes associated with it:

User Class - Holds user properties. Has NO DB related methods (infact
has NO methods, only properties lol) etc
User Collection class - Holds a collection of user objects
User Manager Class - Performs all Saving/Loading/Creating operations
for a user object/collections.

Should I have all the functions/methods in User Manager class inside
the User class? I read some where that this is the BEST way and that I
should stop using a "manager" class because its the "old technique" of
coding back in the days of fortran.

Also, if I use a single class like User and store it in the
session...does it store all the methods and functions too? That could
be very costly.

A good thing I guess about having the 3 classes is that my DAL is
implemented in only the User Manager class.
So is single or multiple classes better?

May 29 '06 #2
>
Also, if I use a single class like User and store it in the
session...does it store all the methods and functions too? That could
be very costly.


The *code* is stored once per application, no matter how many instances
you have. In the heap (or on the stack - for ValueType variables) only
"data" is stored, so adding methods does not alter the amount of heap
used.

Hans Kesting
May 29 '06 #3
On 28 May 2006 21:28:41 -0700, vz******@verizon.net wrote:
I have many types of classes and I'm deciding whether to use a single
class or multiple classes for EACH type of class.

For an example:

User class has 3 classes associated with it:

User Class - Holds user properties. Has NO DB related methods (infact
has NO methods, only properties lol) etc
User Collection class - Holds a collection of user objects
User Manager Class - Performs all Saving/Loading/Creating operations
for a user object/collections.

Should I have all the functions/methods in User Manager class inside
the User class? I read some where that this is the BEST way and that I
should stop using a "manager" class because its the "old technique" of
coding back in the days of fortran.

Also, if I use a single class like User and store it in the
session...does it store all the methods and functions too? That could
be very costly.

A good thing I guess about having the 3 classes is that my DAL is
implemented in only the User Manager class.
So is single or multiple classes better?


I still do this kind of seperation, to separate managing the data from
the data itself.
- Business object: holds properties, business rules
- Business object collection: strongly typed collection of a business
object (inherit from Collectionbase)
- Data manager: read/write to database

Of course, in 2.0 the Business object collection can be replaced by a
generic collection.

I like the fact that my business objects are not bound to a specific
data behavior.
--
Ludwig Stuyck
http://www.coders-lab.be
May 29 '06 #4
As for being replaced by a generic collection. In my experience in the
domain layer it is always best to close the type for a collection ... i.e.

public class UserCollection : Collection<User> {}

Even if you are not adding functionality as you may need to add collection
behaviors in the future. It is also considerred bad practice by many to
return something like Collection<User> from the domain layer.

Cheers,

GReg
"Ludwig" <no**@none.com> wrote in message
news:dr********************************@4ax.com...
On 28 May 2006 21:28:41 -0700, vz******@verizon.net wrote:
I have many types of classes and I'm deciding whether to use a single
class or multiple classes for EACH type of class.

For an example:

User class has 3 classes associated with it:

User Class - Holds user properties. Has NO DB related methods (infact
has NO methods, only properties lol) etc
User Collection class - Holds a collection of user objects
User Manager Class - Performs all Saving/Loading/Creating operations
for a user object/collections.

Should I have all the functions/methods in User Manager class inside
the User class? I read some where that this is the BEST way and that I
should stop using a "manager" class because its the "old technique" of
coding back in the days of fortran.

Also, if I use a single class like User and store it in the
session...does it store all the methods and functions too? That could
be very costly.

A good thing I guess about having the 3 classes is that my DAL is
implemented in only the User Manager class.
So is single or multiple classes better?


I still do this kind of seperation, to separate managing the data from
the data itself.
- Business object: holds properties, business rules
- Business object collection: strongly typed collection of a business
object (inherit from Collectionbase)
- Data manager: read/write to database

Of course, in 2.0 the Business object collection can be replaced by a
generic collection.

I like the fact that my business objects are not bound to a specific
data behavior.
--
Ludwig Stuyck
http://www.coders-lab.be

May 29 '06 #5

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

Similar topics

9
by: Aguilar, James | last post by:
I know that one can define an essentially unlimited number of classes in a file. And one can declare just as many in a header file. However, the question I have is, should I? Suppose that, to...
2
by: Hollywood | last post by:
After doing a search through google's archives of this list, I didn't see what I was looking for so here goes... Is it possible to serialize/deserialize multiple objects from a single XML file? ...
15
by: Sinex | last post by:
Hi, Why does C# disallow multiple inheritance? Whats the reason behind this? Is there any advantage or is it just a method to avoid some problems (if so, what problems?) that come with multiple...
7
by: jsale | last post by:
I have made an ASP.NET web application that connects to SQL Server, reading and writing data using classes. I was recommended to use session objects to store the data per user, because each user...
2
by: John Granade | last post by:
I'm looking for the best way to make a dataset available from multiple Windows forms. The dataset is created from an XML file. I have a main form (frmMain) that loads the dataset and reads the...
2
by: Andrea | last post by:
Suppose a base class like partial class X : Page ... and a class A that is called from class X somewhere along the code. I'm not able to understand if for each user connected to the web...
4
by: Matt Kruse | last post by:
While developing an internal IE6-only webapp, a discussion started about the 'best' way to apply classes to data tables across multiple pages. The two arguments were: 1. Apply a single class to...
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...
4
by: Alan Mailer | last post by:
Again, I'm new to VB.net and there is something I need help with: Like (I assume) many of us, over time I want to be able to create some VB.net classes that I might want to use in more than one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.