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)