Utility function for defining S3 methods