Search code examples
oopdesign-patternsclass-designfmod

Class Design - The responsibilities for the classes


Say, I have 2 classes which are Audio and AudioManager. My question is, should these functions

void Play();
void Resume();
void Pause();
void Stop();
void Load();

be within Audio class or AudioManager?

Well, what I did is put them all into AudioManager class, but I'm not so sure about it.


Solution

  • Think about them as if they were real word concepts. In fact they are. If you insert your CD to a CD Player will you tap the CD or the Player? Of course the Player. The functions you listed belong to the player.

    I think that the name AudioManager does not describe its task. In general the use of the name Manager is discouraged since it is a broad concept. In your case Player would be better.

    Audio in your case is just a data structure and should not have those functions.

    Just a remark: most of the functions in your post are straightforward but Load is somehow confusing. Does It load a track or it loads the CD into the player or?