title: Creating Objects exclusively with Factory
body: <p>I'm currently working on a student project and wondering if there is a way to create objects exclusively with factory methods?</p>
  
  <pre><code>public class PersonFactory {
  
      public static Person createPerson() {
          // some constraints ...
          return new Person();
      }
  
  }
  </code></pre>
  
  <p>My exemplary <code>PersonFactory.java</code> is supposed to return <code>Person</code> objects with its <code>createPerson()</code> method.</p>
  
  <pre><code>public class Person {
  
      // some examples ...
      private String name;
      private int age;
  
      public Person() {
          // ...
      }
  
  }
  </code></pre>
  
  <p>This works fine, but in the <code>main</code> program, I am still able to create <code>Person</code> objects with their common constructor (since it is <code>public</code>). But if I change the constructor to <code>private</code>, the factory method cannot access it either.</p>
  
  <pre><code>public class PersonManagement {
  
      public static void main(String[] args) {
          // both still works ...
          Person p1 = new Person();
          Person p2 = PersonFactory.createPerson();
      }
  
  }
  </code></pre>
  
  <p>Thank you so much in advance ;)</p>