dimanche 15 novembre 2020

Is it a good practice to write the factory method inside the interface?

Is it a good practice to implement the factory method on the interface itself?

Is it scalable? Or unnecessarily coupled?

public interface MyInterface {

  default MyInterface createDefaultImpl() {
    return new DefaultImpl();
  }

}

For sure it would be a problem if the creation method had parameters, adding dependencies/coupling to the interface.

In case of a simple no-args constructor, I`m not really sure.

Aucun commentaire:

Enregistrer un commentaire