Factory updating the created objects, any design pattern fulfilling this?

I'm in the process of implementing the factory design pattern, but wanted to know if another design pattern could fulfil my requirements.

What I have to do is: 1. Create multiple instances of a class containing a thread. The difference in the instances is the frequency the thread is run. 2. Each instance contains a list of references which can be updated by adding and deleting, these add and delete are called from the fabric as it holds the knowledge of the created classes. (This is where I hope for maybe another design pattern, as the responsibility of the fabric is increased)

I could of course implement a repository that holds a list with the generated instances and have that update the instances ?

But is there a design pattern that extends the fabric with an update kind of functionality ?


I'm not sure to understand your requirement. If you are creating multiple instances of the same class, the Factory (whether you mean "Abstract Factory" or "Factory Method") is not the pattern that fits your requirement.

If the multiple objects you are creating were not mutable, I would have suggested the Flyweight pattern (http://en.wikipedia.org/wiki/Flyweight_pattern).

Depending on how complex it is to create your objects, and how different your objects are one from the other, you may want to consider using the Prototype pattern (clone vs create new).

One of your requirement is to provide a clean interface that provide the necessary functions to manipulate your objects. For this, the Facade pattern is what you want.

Most of the time, a single pattern is not enough to solve all your problems. You often need to combine multiple of them, and create your own. The patterns are just guides.

链接地址: http://www.djcxy.com/p/33650.html

上一篇: 位图大小超过虚拟机预算

下一篇: 工厂更新创建的对象,实现此目的的任何设计模式?