473,624 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2218
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******@veriz on.net> wrote in message
news:11******** **************@ j55g2000cwa.goo glegroups.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******@verizo n.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...do es 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.co m> wrote in message
news:dr******** *************** *********@4ax.c om...
On 28 May 2006 21:28:41 -0700, vz******@verizo n.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...doe s 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
6632
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 use the common example, I have a situation where I am implementing many types of Shapes. My current way of thinking is, well, since they are all the same type, let's just put them all in the same file. The include file would be "shapes.h" and it...
2
11676
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? I was looking to use the XML serialization to be able to translate complex XML elements in a single XML file through XML serialization as opposed to using SAX and coding my own serializer. However, the XML Serialization API appears to only...
15
7185
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 inheritance? regards, Sinex
7
2153
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 using the application needs to see their own data only. My problem is that when multiple users are in the application, when in the session object, data is fine, however as there is only one instance of the class files, when data is put into them,...
2
6896
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 data but then I have other forms that give the ability to add, modify, and delete rows. This of course changes the dataset and I need that reflected in the main form. At first I was actually passing a reference of the dataset to the "modify" form...
2
1551
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 site, a thread is created and so every call to class A stay in different thread or all works into a single thread.
4
4691
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 each table. That class (possibly in combination with other classes on child elements) controls every part of the table - layout, colors, fonts, etc. Example: class="data" PROS: Easier to standardize, less specificity confusion, everything is...
6
2067
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 DeviceManager which is only interested in CD/DVD devices. I want to get the list of CD/DVD devices and "be informed when a disc inserted into a device". I am developing this on Linux. So, I used HAL API and read some system (actually /proc) files to gather...
4
4459
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 Project. So let's say I've created a Folder called "MyVBNet Classes" to hold these general-use VB.Net class files that I will eventually associate with various Projects I create. Now let's imagine I've created a class called "MyClass.vb" that...
0
8182
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8688
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6115
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.