Adding security code to the object factory method