The concept of using a factory for producing objects is part of a Design Pattern often used in OOP languages such as Java.
It has several advantages compared with direct object instantiation.
- Hides the details of object instantiation
- Provides the ability to return a subtype of the factory’s return-type
- Optionally returning an existing object rather than a new object
Dart makes it easy and convenient to create factory constructors using the “factory” keyword.
Read more about using the Factory pattern here: