Implement infer_class