title: Swift Objects initialization (Class factory method, default init, convenience init)
body: <p>I'm trying to figure out the best pattern to work with objects in Swift.</p>
  <p>i think i got it right with the initializers, both convenience and default... but what happen with the class factory methods?</p>
  <p>I tried to create a simple class Person and a subclass Student, with few properties and methods. is it the most correct way to do it?</p>
  <pre><code>   class Person{
      
      var _name: String
      var _surname: String
      var _dateOfBirthday: String
      var _phoneNumb: [String]
      
      init(name:String, surname:String, dateOfBirthday:String, phone:[String]){
          self._name = name
          self._surname = surname
          self._dateOfBirthday = dateOfBirthday
          self._phoneNumb = phone
      }
      
      convenience init() {
          self.init(name:&quot;&quot;,surname:&quot;&quot;,dateOfBirthday:&quot;&quot;, phone:[])
      }
      
      convenience init(name:String){
          self.init(name:name,surname:&quot;&quot;,dateOfBirthday:&quot;&quot;, phone:[])
      }
      
      
  }
  
  
  
  class Student:Person{
      
      var _studentId:Int
      
      init(name: String, surname: String, dateOfBirthday: String, phone: [String], id:Int) {
          self._studentId = id
          super.init(name: &quot;&quot;, surname: &quot;&quot;, dateOfBirthday: &quot;&quot;, phone: [])
      }
      
      convenience init(){
          self.init(name: &quot;&quot;, surname: &quot;&quot;, dateOfBirthday: &quot;&quot;, phone: [], id:0)
      }
      
      convenience init(name:String){
          self.init(name:name,surname:&quot;&quot;,dateOfBirthday:&quot;&quot;, phone:[], id:0)
      }
      
  }
  </code></pre>
  <p>what if i want to add a class factory method? would it be something like this or i'm doing it wrong?</p>
  <pre><code>class func Person() -&gt; Person {
   var x = Person()
   x._telephoneNumber = [String]() // is this needed? or i can initialize it later?
   return x
  }
  
  class func PersonWithName(name:String) -&gt; Person {
   var x = Person(name:name, surname:&quot;&quot;, dateOfBirthday:&quot;&quot;, telephoneNumber:[])
   return x
  }
  </code></pre>
  <p>is this correct? why would it be better to use the init instead of the class factory?</p>