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
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
Perhaps a factory pattern which has some kind of ceiling of how many objects it can produce under a given circumstance.
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#
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!).