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:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store