开发者

"Convenience" Functions

Several parts of my library come with "convenience" functions. For example, a container class might have a function to parse information from a string. These functions are not necessarily needed (or wanted) all开发者_Python百科 the time, so I'd like to put them in separate files so they can be included or left out according to the users' needs.

How should this be structured? Should I put all the "convenience" stuff in header files in a separate folder? Or perhaps it belongs in a completely separate library...?

How do big libraries (like Boost) handle this sort of thing? Or do they just avoid it altogether?


"Should" is a word which tends to provoke religious responses, but I think you'll be better off thinking about this as though you were a user of your library.

How would you want it to be structured? Everything in one api so you can find it, or scattered around the classpath?

Is there any real reason to even consider putting (for example) your container class's "parseString" method anywhere else than in the container class?


It's common for library providers to organize their library into logical pieces, but then provide a way to include the entire library in one go (in C/C++, a single header file; in Ruby, a single include, &c.). This allows for good cohesion, and allows library users to include just the pieces they need, if they desire.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜