I am currently working on a student project and am wondering if there is a way to create objects exclusively using factory methods?
public class PersonFactory { public static Person createPerson() {
My example PersonFactory.java should return Person objects using the createPerson() method.
public class Person {
This works fine, but in the main program, I can still create Person objects with their common constructor (since this is public ). But if I changed the constructor to private , the factory method will also not be able to access it.
public class PersonManagement { public static void main(String[] args) {
Thank you very much in advance;)
source share