I am currently working on a software project that performs compression and indexing on video surveillance footage. The compression works by splitting background and foreground objects, then saving the background as a static image, and the foreground as a sprite.
Recently, I have embarked on reviewing some of the classes that I have designed for the project.
I noticed that there are many classes that only have a single public method. Some of these classes are:
- VideoCompressor (with a
compressmethod that takes in an input video of typeRawVideoand returns an output video of typeCompressedVideo). - VideoSplitter (with a
splitmethod that takes in an input video of typeRawVideoand returns a vector of 2 output videos, each of typeRawVideo). - VideoIndexer (with an
indexmethod that takes in an input video of typeRawVideoand returns a video index of typeVideoIndex).
I find myself instantiating each class just to make calls like VideoCompressor.compress(...), VideoSplitter.split(...), VideoIndexer.index(...).
On the surface, I do think the class names are sufficiently descriptive of their intended function, and they are actually nouns. Correspondingly, their methods are also verbs.
Is this actually a problem?
MyMathModule what_does_this_even_mean;. I know only one reason to use classes, and it's rarely applicable: Grouping template arguments to reduce typing (namespaces can't be passed to templates). In any case, this argument falls flat for a single-method class; you typically wouldn't create a module for this single function but rather put it where you'd put that module (i.e.foo::barinstead offoo::bar::bar). – Jan 29 '14 at 12:01Videoclass? I think we both agree that this is obviously not the case here. – Doc Brown Jan 29 '14 at 13:03Classname::again and again into your cpp files). In Java or C# using a "class" for grouping functions is not more effort than using a namespace in C++. But with a class, you are ready when your video compressor "version 1.1" needs some state (like compression parameters etc.), is used in multithreaded environment, etc. – Doc Brown Jan 30 '14 at 10:50