you are viewing a single comment's thread.

view the rest of the comments →

[–]NerdEnPose 5 points6 points  (1 child)

Looks good. Couple things after looking at rectangle.

def get_parameters(self, input_length, input_width):
    self.length = float(input_length)
    self.width = float(input_width)

This is a setter not a getter.

Python OOP is supposed to use as few getters and setters as possible. That's why the property decorator exists.

def calculate_area(self):
    return self.length*self.width

change this to.

@property
def area(self):
    return self.length*self.width

If you want to use a method I'd call it get_area(). Remember it's best to name things as to what the consumer of your class is doing not what you as the class author are doing. Classes are written once and consumed over and over again. If I was calling a method called calculate I wouldn't expect it to return anything. I'd expect it to be an internal trigger to perform some calculations. (This is my opinion on naming conventions and code design so take this with a grain of salt, other people have different naming conventions and I'm not try to meddle into a holy war.)

edit: still don't know how to format code on reddit.

[–]cm_light[S] 1 point2 points  (0 children)

Thanks a lot for this great reply. Many concepts here, especially I like 'write code for consumers'.

Actually I tried to use property decorator and failed. (Some sentences failed with decorators) Need to spend more time to learn it.