Is the word “Helper” in a class name a code smell?

前端 未结 6 841
别跟我提以往
别跟我提以往 2020-12-24 05:28

We seems to be abstracting a lot of logic way from web pages and creating \"helper\" classes. Sadly, these classes are all sounding the same, e.g

ADHelper, (Active D

6条回答
  •  一向
    一向 (楼主)
    2020-12-24 05:50

    In many cases, I use classes ending with Helper for static classes containing extension methods. Doesn't seem smelly to me. You can't put them into a non-static class, and the class itself does not matter, so Helper is fine, I think. Users of such a class won't see the class name anyway.

    The .NET Framework does this as well (for example in the LogicalTreeHelper class from WPF, which just has a few static (non-extension) methods).

    Ask yourself if the code would be better if the code in your helper class would be refactored to "real" classes, i.e. objects that fit into your class hierarchy. Code has to be somewhere, and if you can't make out a class/object where it really belongs to, like simple helper functions (hence "Helper"), you should be fine.

提交回复
热议问题