javaeclipseeclipse-emfemfeclipse-emf-ecore

Why use a factory instead of 'new'?


I am reading the book EMF: Eclipse Modeling Framework where its stated:

The EMF programming model strongly encourages, but doesn’t require, the use of factories for creating objects. Instead of simply using the new operator to create [an object]...

Why is the use of factories encouraged over new?

Your answer does not have to be EMF specific, as long as it has to do with Java.


Solution

  • You can read Effective Java Item 1: Consider static factory methods instead of constructors. It describes advantages of using factory methods in detail: