I think the concept is called overloading. Right now I'm writing a class that will provide getter and setter methods, and am stuck on a design issue.
Both methods are one-liners that simply set a value, or return a value.
def set_number(self, num): self.count = num def get_number(self): return self.count
Would it be better to save space and make the class "look" smaller by doing something that will basically combine the two methods into one and then just decide which line should be executed depending on whether the num argument is provided?
Or should I just stick to clarity and keep them separated? Some people feel that it's a "waste of space" to keep all these one-liners on their own, while others disagree and prefer splitting them up.
Any reasons why I would choose one or the other?
@property. It will simplify this for you and remove all the hand-wringing.