{"id":15,"date":"2020-07-19T06:30:05","date_gmt":"2020-07-19T06:30:05","guid":{"rendered":"https:\/\/system.camp\/index.php\/2020\/07\/19\/consider-static-factory-methods-instead-of-constructors-when-creating-objects\/"},"modified":"2020-10-06T09:56:51","modified_gmt":"2020-10-06T09:56:51","slug":"consider-static-factory-methods-instead-of-constructors-when-creating-objects","status":"publish","type":"post","link":"https:\/\/system.camp\/tutorial\/consider-static-factory-methods-instead-of-constructors-when-creating-objects\/","title":{"rendered":"Consider static factory methods instead of constructors when creating objects"},"content":{"rendered":"\n

What is the most common way to create an object of a class? Yeah, you probably guessed it right! By using a constructor. But is it always the best way? We\u2019ll find out here!<\/p>\n\n\n\n

Another way to create objects of a class is by using a public static factory method. This method creates an instance of a class and then returns it. Providing a static method has its own set of advantages and disadvantages.<\/p>\n\n\n\n

Let us first discuss the advantages:<\/p>\n\n\n\n