Sign in to follow this  

Design Issue

Recommended Posts

Concentrate    181
I have a class called MusicPlayer. The whole application might need to access a music player. Although there could be multiple musicPlayer object, as I write the code, there will be only one music player object.
So I ask how to fit this musicPlayerObject into my application. I have a couple of ideas, maybe one of this is a good one? I need your thoughts please.

Option # 1 -- create a function in music player class to retrive a globally used object
class MusicPlayer{
MusicPlayer& getObject(){ static MusicPlayer m; return m; }
Option # 2 -- create a header in which a namespace manages all global variable used
namespace GlobalVariable{
MusicPlayer musicPlayer;

Option # 3, use extern keyword
class MusicPlayer{
extern MusicPlayer musicPlayer
and define it in musicplayer.cpp

or some other method? Any suggestion or comments.

This problem comes up often and I would like a good solid solution.

regards, D.Chhetir

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this