DEV Community

sumandari
sumandari

Posted on

When should I refactor my code into a decorator

Continue reading the book, this is a very good book. I suggest you to read it too.

It says:

  1. don’t create a decorator in the first place. Wait until you see the pattern.
    Yes, I totally agree. I created a decorator for user login and payload validation after I used it everywhere and found the pattern.

  2. Create the decorator if it will be used more than three times.
    Okay, that also make senses. Why should I create a decorator if I only use the logic once.
    Not sure if it’s twice. But three is a fair number for me.

  3. Keep the code in decorator minimum.
    Too much line and logic will give me a headache when applying a decorator.

Top comments (0)

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay