1

I have an object, which is part of another object (think bricks which make up a house).

I want to "throttle" the creation of bricks so only a certain amount can be used per house creation. Is there a design pattern to do this?

Thanks

GurdeepS
  • 65,107
  • 109
  • 251
  • 387
  • either have a class the brick class keep tracks of how many instance there are by using static int, or better, use the class that manages the creation of bricks to check the number of created bricks and only create new ones when the current number of bricks is less than the maximum number of bricks...my 2 pence – George Profenza Dec 13 '10 at 03:38

3 Answers3

3

Perhaps a factory pattern which has some kind of ceiling of how many objects it can produce under a given circumstance.

JimDaniel
  • 12,513
  • 8
  • 61
  • 67
0

Although it is not the same, your question is similiar to bandwidth throttling. I may suggest a question asked before about it: Bandwidth throttling in C#

Community
  • 1
  • 1
Utku Zihnioglu
  • 4,714
  • 3
  • 38
  • 50
0

If you're building multiple houses, you need to keep track of the bricks as an appropriate member of the house. If you're only building one house, a static member in the brick class will work. There are more 'elegant' ways to achieve this, depending on your actual aim. You could modify the Singleton pattern (on the brick class) to accomplish this (even if you're building many houses!).

red
  • 41
  • 2