Pregunta

However, there are some classes that should have only one instance.

Sometimes they are factories, which you can use to create the other objects in the system.

If more than one factory exist, clerical control over the created objects may be compromised.

From : Agile software development : PPP

What clerical control Uncle Bob talks about, that would be compromised?

¿Fue útil?

Solución

Whatever kind of "clerical control" your application needs. If you don't know what that means, chances are high your application won't need such control ;-)

For example, this could mean to keep account on the whole set of objects of a certain type which were created during the lifetime of your application, for the purpose of reiterating over them at a later point in time, or for searching for an existing object. Morevover, this could be used to create something like an "object cache" for objects where the creation is costly, like objects from a database. So the accounting will allow you to check if an object must really be newly created, or if you can reuse a former instance from the cache.

Other possible scenarios are the example of MetaFight's comment, easier ID number generation, or just counting the number of created objects of a certain type for statistical purposes.

I guess once you got the idea, you can extend that list easily by yourself.

Licenciado bajo: CC-BY-SA con atribución
scroll top