Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / April 2006

index in the constructor

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave Johnson - 05 Apr 2006 11:14 GMT
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
Laura T. - 05 Apr 2006 11:28 GMT
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

> greetings fellow developers,
>
[quoted text clipped - 12 lines]
> Sent via .NET Newsgroups
> http://www.dotnetnewsgroups.com 
Vadym Stetsyak - 05 Apr 2006 11:40 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.