-
November 7th, 2010, 08:48 PM
#1
Design Question
I am doing this under academic setting.
I have about 10 classes doing different jobs. However, there are some functions which are called by a couple of classes so I have declared them under a different header and are global function. Is this a bad design to leave some functions floating around as they are common to a number of classes.
I would like to declare them under a class name but them how do I share those functions among different classes?
Is too much use of static function a design problem as well? I have some functions which are being used by different classes various times.
Last edited by Learned; November 7th, 2010 at 09:16 PM.
-
November 8th, 2010, 02:05 AM
#2
Re: Design Question
Hi,
if you wish to centralize some functions called by some different classes you can declare a helper class. Each class using this helper class can either inherit from it (in cpp multiple inheritage is possible) or make use of the helper class (via a member). This member can be a reference, a pointer or a (static) member.
Sometimes I have a helper class that has only static functions: Then I do not need any instance of this class.
So there are many ways to have helper functions in a class and I think that is a better design than having global functions. Which one is the best depends on the situation.
With regards
Programartist
-
November 8th, 2010, 07:09 AM
#3
Re: Design Question
What about using a singleton class for these functions? Isn't this the purpose of the Singleton classes?
Last edited by SkyNetTo; November 8th, 2010 at 07:54 AM.
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
|