CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Design Question

  1. #1
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    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.

  2. #2
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    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

  3. #3
    Join Date
    Mar 2008
    Location
    Turin / Italy
    Posts
    178

    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
  •  





Click Here to Expand Forum to Full Width

Featured