Creates a factory method for a class