|
-
August 26th, 2011, 08:05 AM
#1
Singleton? Static member pointer? Design question...
I have an object that lives throughout the life of an app. There are also DLLs that access the object to read _and_ write it. It is a pointer and is a data member of the Application (CWinApp). Obvisously this is not ideal and I inherited it, so Id like to address the issue, as currently there are AfxGetApp() calls everywhere and its ugly.
Suggestions? Where should the object live? and how best to access it?
Thx.
-
August 26th, 2011, 08:30 AM
#2
Re: Singleton? Static member pointer? Design question...
I am stupid and don't know anything about you problem, I hope to know but I can never, calling a function multiple times when needed is better than calling once to be used by all
-
August 26th, 2011, 08:45 AM
#3
Re: Singleton? Static member pointer? Design question...
I am stupid and don't know anything about you problem
awesome
-
August 27th, 2011, 12:39 AM
#4
Re: Singleton? Static member pointer? Design question...
Well, it sounds like singletone is a way to do that. Besides, 'read' and 'write' functions exported from main app will allow dlls exchange data with the object in safe manner.
Best regards,
Igor
-
August 27th, 2011, 12:56 AM
#5
Re: Singleton? Static member pointer? Design question...
 Originally Posted by gareth19
awesome
You at least need to learn to say thanks for what people post to help you. Your complement on such negative thinking about self only shows how low your common sense actually is.
hi,,,
-
August 27th, 2011, 06:45 PM
#6
Re: Singleton? Static member pointer? Design question...
 Originally Posted by gareth19
I have an object that lives throughout the life of an app. There are also DLLs that access the object to read _and_ write it. It is a pointer and is a data member of the Application (CWinApp). Obvisously this is not ideal and I inherited it, so Id like to address the issue, as currently there are AfxGetApp() calls everywhere and its ugly.
Suggestions? Where should the object live? and how best to access it?
Thx.
In MFC, there is nothing wrong with following this approach.
The CWinApp object is essentially a singleton and the best practice way to access it is AfxGetApp().
So AfxGetApp()->GetMyClass()->DoSomeWork() is perfectly fine.
If you made this a singleton, it would be something like MyClass::GetInstance()->DoSomeWork() which isn't significantly better than what you already have.
If you keep the AfxGetApp() approach, you have something that is well understood by anyone that programs with MFC.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|