Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think Composite pattern (<a href="http://en.wikipedia.org/wiki/Composite_pattern" rel="nofollow">http://en.wikipedia.org/wiki/Composite_pattern</a>) is better for your needs.</p> <p>It would be some variation like this (naming is a bit screwed in terms of pattern, but they are more like your code this way):</p> <pre><code>class Activity { public: virtual ~Activity(); virtual void start(); virtual void add(Activity*); virtual void remove(Activity*); private: Activity(); } class ActivityManager : Activity { public: ConcreteActivity(); ~ConcreteActivity(); void start(); void add(Activity*); void remove(Activity*); private: list&lt;Activity*&gt; _activities; } void ActivityManager::start() { list&lt;Activity*&gt;::const_iterator concreteActivity; for(concreteActivity = _activities.begin(), concreteActivity != _activities.end(); ++concreteActivity) { *concreteActivity-&gt;start(); } } void ActivityManager::add(Activity* newActivity) { _activities.push_back(newActivity); } void ActivityManager::remove(Activity* activityToDelete) { _activities.remove(activityToDelete); } class SomeActivity : Activity { public: SomeActivity(); ~SomeActivity(); void start(); } class OtherActivity : Activity { public: OtherActivity(); ~OtherActivity(); void start(); } </code></pre> <p>And the example of usage:</p> <pre><code>ActivityManager* manager = new ActivityManager(); SomeActivity* activity_one = new SomeActivity(); OtherActivity* activity_two = new OtherActivity(); manager-&gt;add(activity_one); manager-&gt;add(activity_two); manager-&gt;start(); </code></pre> <p>And you still can make ActivityManager the Singleton, if you want. Without any additional info on your project, can't think of a better way.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload