less than 1 minute read

What I Learned

Class Methods

  • @classmethod uses cls to operate at the class level.
  • Good for alternative constructors and factory patterns.

Static Methods

  • @staticmethod doesn’t take self or cls.
  • Best for utility functions that belong with a class, but don’t need instance data.

Decorators

  • A decorator wraps another function.
  • I used *args and **kwargs to make them flexible and reusable.

What I Thought About

I realized how these tools help keep class code clean and focused. Instead of adding random helper functions outside the class, I can now organize them inside with clear roles.

Decorators were tricky at first, but once I understood that functions are objects in Python, it clicked. It made me think of all the places I’m repeating checks or logging — and how decorators could simplify that.

What I Want to Do Next

  • Use classmethods to manage object creation with data loading.
  • Add decorators to log or validate user input in CLI apps.
  • Compare decorator functions with middleware-style ideas in web frameworks.

Tags:

Updated: