Is it a good practice to define properties in an interface like this?
class MyInterface(object):
def required_method(self):
raise NotImplementedError
@property
def required_property(self):
raise NotImplementedError
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’d use a ABC class for that, but yes; you can even use a
@abstractpropertyfor that very use-case.Subclasses of the ABC are still free to implement
required_propertyas an attribute instead; the ABC will only verify the existence ofrequired_property, not what type it is.