PC Review


Reply
Thread Tools Rate Thread

index in the constructor

 
 
Dave Johnson
Guest
Posts: n/a
 
      5th Apr 2006
greetings fellow developers,

how to limit the number of objects that can be build from a class???

is anyone familiar with this problem, i guess that it has somthing to do
with indexing the objects while instantiated, i am i correct ??? or
there is any other way ??

if someone came accross this problem before it would be nice to explain
how he\she solved this issue have fun!

Sharing makes All the Difference

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
 
Reply With Quote
 
 
 
 
Laura T.
Guest
Posts: n/a
 
      5th Apr 2006
Make the constructor of the object private so that it can't be instantiated
via new.
Then add a static CreateObject() method that counts the number of objects
created so fat and if exceeded throws an exception.
This way the users of the object must call
BrandNewObject=LimitedObject.CreateObject(); to have an instance and this
way your CreateObject method can control the number of objects at large.

Laura

"Dave Johnson" <(E-Mail Removed)> ha scritto nel messaggio
news:(E-Mail Removed)...
> greetings fellow developers,
>
> how to limit the number of objects that can be build from a class???
>
> is anyone familiar with this problem, i guess that it has somthing to do
> with indexing the objects while instantiated, i am i correct ??? or
> there is any other way ??
>
> if someone came accross this problem before it would be nice to explain
> how he\she solved this issue have fun!
>
> Sharing makes All the Difference
>
> --
> Sent via .NET Newsgroups
> http://www.dotnetnewsgroups.com



 
Reply With Quote
 
Vadym Stetsyak
Guest
Posts: n/a
 
      5th Apr 2006
Hello, Dave!

DJ> how to limit the number of objects that can be build from a class???

DJ> is anyone familiar with this problem, i guess that it has somthing to
DJ> do with indexing the objects while instantiated, i am i correct ??? or
DJ> there is any other way ??

DJ> if someone came accross this problem before it would be nice to explain
DJ> how he\she solved this issue have fun!

If I correctly understood the question:

One of the solutions here will be object factory, that will track necessary objects count.

Another one will be incrementing class static counter and if limit is exceeded throw exception in the constructor with
appropriate message.


--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# constructor best practice: how much logic to place in a C#constructor Jon Microsoft C# .NET 2 11th Nov 2009 10:18 PM
overloaded constructor, access zero-argument constructor mblatch Microsoft C# .NET 3 8th Apr 2005 10:53 PM
Calling a struct constructor in a class constructor body Karl M Microsoft VC .NET 4 19th Dec 2004 02:21 PM
Calling overloaded constructor with values inside another constructor Tristan Microsoft C# .NET 2 30th Mar 2004 02:05 PM
exception during sorting data in a data grid in the constructor of the System.Data.Index class Frank Microsoft Dot NET Framework 0 30th Sep 2003 03:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:22 PM.