pythonoopobject-oriented-analysis

Proper way to Implement a Birthday Class in Object Oriented Python


I have the following class

class Dob:
    def __init__(self):
        self.welcome_text = ""
    
    #Computes DOB
    def calc_dob(self):
        pass

    #Get User Input
    def get_input(self, msg):
        pass

    def __repr__(self):
        print(self.welcome_text)
        total_days = self.calc_dob()
        return str(total_days)

And calls it like this:

if __name__ == "__main__":
    print(Dob())

Initially I thought this is OK but importing it into PyCharm IDE, it shows warning that methods calc_dob and get_input could be static.

Following the IDE's suggestion, it moves the methods outside of the class.

All that is left is the __repr__ method .That makes me think something is wrong with the Class above.

Is the code OK, and I should just rather mark the methods with @staticmethod annotation? or my idea isn't Object Oriented and how can I make it Object Oriented.

Any help will be appreciated please.

EDIT: I remove the codes (implementation for the methods) for simplicity in posting here. The reasons for the warning are that I am not using instances of the Class. What I'm asking is if this is a proper Implementation


Solution

  • I think a DoB object should have one job: hold the date of birth. Question is if this even needed. We have date objects for this already. Calculations on DoB would rather live in a DOBHelper object or function. The reason pycharm moves the methods is because you are not using any class variables in them.