vendredi 6 mai 2022

What is a "free object"?

Source: https://refactoring.guru/design-patterns/factory-method

I was wondering what the exact definition of a "free object" was in below context, and what free objects in general meant.

Context

Use the Factory Method when you want to save system resources by reusing existing objects instead of rebuilding them each time.

You often experience this need when dealing with large, resource-intensive objects such as database connections, file systems, and network resources.

Let’s think about what has to be done to reuse an existing object:

  1. First, you need to create some storage to keep track of all of the created objects. When someone requests an object, the program should look for a free object inside that pool. … and then return it to the client code. If there are no free objects, the program should create a new one (and add it to the pool). That’s a lot of code! And it must all be put into a single place so that you don’t pollute the program with duplicate code.

Aucun commentaire:

Enregistrer un commentaire