• Post Reply Bookmark Topic Watch Topic
  • New Topic

don't create too much object?  RSS feed

 
manas ranjan mandal
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i don't want to create 150 object of my class then what i will do?

Thanks in advance
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
don't create them.

seriously, i don't understand the question. who or what is making you create 150? and why don't you want to do that?
 
madura shantha
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you need to limit the number of objects to be created?
If that is your problem, I don't think you can do that.
but you can call the garbage collector when you need to remove unnecessary objects.but it also not guaranteed.
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Erm, I can think of a couple of ways to limit the number of instances of a class.
 
manas ranjan mandal
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gavin can you tell me the various ways where i can limit the number of instance to be created?
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it would be better if you figured it out for yourself so I wont give you the answer, but some pointers.

What I would do, is I would keep in mind the Singleton Pattern, which allows you to ensure only one instance of an object is created.

I would also consider the (Abstract) Factory/Factory Method Pattern, this allows you to "control" the creation of objects to some degree, usual used to delay the dicession over which implementation of a class to create until run time.

Hope this helps, give it some thought, and post back with what ideas you come up with.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!