DEV Community


Discussion on: Applying Open-Closed Principle with Decorator Pattern in Typescript

lifelongthinker profile image

This is a very common (and useful!) pattern, indeed. And you summarized it pretty well 👏.

I'd like to add one point. Do you really name your class AuthorizationHttpPostClientDecorator? or was that just for educational purposes?
I ask because I frequently see pattern implementations in the wild being named after the patterns (instead of using proper names according to WHAT, as in this case, is being decorated and WHY).

To me, it feels much more natural to call this class something along the lines of AuthorizedHttpPostClient or AuthHttpPostClient, which would hint at the purpose of the base class, while the decorator is just a means to an end.

joaosczip profile image
joaosczip Author

Yeah, it's just for educational purposes!
I don't like give to a class a very extensive name like that, unless it be inevitable.
But now I see that your tip is also needed for educational purposes too, I'll adopt it for the nexts posts.

Thank you for your feedback, comments like that help me improve a lot.