javafactory-pattern

In what terms does new operator is considered harmful?


Factory pattern is supposed to be used when using new operator for creating object is considered harmful. In what terms does new operator is considered harmful


Solution

  • Using of new operator directly is hardcoding.

    It also means that class is not following single responsibility principle.

    Factories along with interfaces allow long term flexibility:

    Hope this helps.