How to save code duplication in the following scenario ?
say A
and B
are two classes having a common function(say) name
class A(object):
name = 'foo'
@property
def name(self): # the common function
return self.name
similarly B
class B(object):
name = 'bar'
@property
def name(self):
return self.name
One way would be to make a class from which both of them inherit from, and define name
there.
Any good alternatives ?