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

前端 未结 6 852
别跟我提以往
别跟我提以往 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 06:00

    As always, it depends on the context.

    When you work with your own API I would definitely consider it a code smell, because FooHelper indicates that it operates on Foo, but the behavior would most likely belong directly on the Foo class.

    However, when you work with existing APIs (such as types in the BCL), you can't change the implementation, so extension methods become one of the ways to address shortcomings in the original API. You could choose to names such classes FooHelper just as well as FooExtension. It's equally smelly (or not).

提交回复
热议问题