You should study design patterns. There are books and online courses.
The factory pattern is one of the simplest. instead of creating class instances with the new operator, you call a "factory" method to create the instance. typically an interface is returned rather than a class type. It is not uncommon to use a factory for the factory, especially if plugins are used.
a common use besides configuration is unit test mocking.
simple online example: